@ -110,7 +110,7 @@ func TestSyncer_SyncAny(t *testing.T) {
// We start a sync, with peers sending back chunks when requested. We first reject the snapshot
// We start a sync, with peers sending back chunks when requested. We first reject the snapshot
// with height 2 format 2, and accept the snapshot at height 1.
// with height 2 format 2, and accept the snapshot at height 1.
connSnapshot . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
connSnapshot . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : & abci . Snapshot {
Snapshot : & abci . Snapshot {
Height : 2 ,
Height : 2 ,
Format : 2 ,
Format : 2 ,
@ -119,7 +119,7 @@ func TestSyncer_SyncAny(t *testing.T) {
} ,
} ,
AppHash : [ ] byte ( "app_hash_2" ) ,
AppHash : [ ] byte ( "app_hash_2" ) ,
} ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT_FORMAT } , nil )
} ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT_FORMAT } , nil )
connSnapshot . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
connSnapshot . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : & abci . Snapshot {
Snapshot : & abci . Snapshot {
Height : s . Height ,
Height : s . Height ,
Format : s . Format ,
Format : s . Format ,
@ -171,7 +171,7 @@ func TestSyncer_SyncAny(t *testing.T) {
// The first time we're applying chunk 2 we tell it to retry the snapshot and discard chunk 1,
// The first time we're applying chunk 2 we tell it to retry the snapshot and discard chunk 1,
// which should cause it to keep the existing chunk 0 and 2, and restart restoration from
// which should cause it to keep the existing chunk 0 and 2, and restart restoration from
// beginning. We also wait for a little while, to exercise the retry logic in fetchChunks().
// beginning. We also wait for a little while, to exercise the retry logic in fetchChunks().
connSnapshot . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
connSnapshot . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 2 , Chunk : [ ] byte { 1 , 1 , 2 } ,
Index : 2 , Chunk : [ ] byte { 1 , 1 , 2 } ,
} ) . Once ( ) . Run ( func ( args mock . Arguments ) { time . Sleep ( 2 * time . Second ) } ) . Return (
} ) . Once ( ) . Run ( func ( args mock . Arguments ) { time . Sleep ( 2 * time . Second ) } ) . Return (
& abci . ResponseApplySnapshotChunk {
& abci . ResponseApplySnapshotChunk {
@ -179,16 +179,16 @@ func TestSyncer_SyncAny(t *testing.T) {
RefetchChunks : [ ] uint32 { 1 } ,
RefetchChunks : [ ] uint32 { 1 } ,
} , nil )
} , nil )
connSnapshot . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
connSnapshot . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 0 , Chunk : [ ] byte { 1 , 1 , 0 } ,
Index : 0 , Chunk : [ ] byte { 1 , 1 , 0 } ,
} ) . Times ( 2 ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Times ( 2 ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
connSnapshot . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
connSnapshot . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 1 , Chunk : [ ] byte { 1 , 1 , 1 } ,
Index : 1 , Chunk : [ ] byte { 1 , 1 , 1 } ,
} ) . Times ( 2 ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Times ( 2 ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
connSnapshot . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
connSnapshot . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 2 , Chunk : [ ] byte { 1 , 1 , 2 } ,
Index : 2 , Chunk : [ ] byte { 1 , 1 , 2 } ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
connQuery . On ( "InfoSync " , mock . Anything , proxy . RequestInfo ) . Return ( & abci . ResponseInfo {
connQuery . On ( "Info" , mock . Anything , proxy . RequestInfo ) . Return ( & abci . ResponseInfo {
AppVersion : 9 ,
AppVersion : 9 ,
LastBlockHeight : 1 ,
LastBlockHeight : 1 ,
LastBlockAppHash : [ ] byte ( "app_hash" ) ,
LastBlockAppHash : [ ] byte ( "app_hash" ) ,
@ -252,7 +252,7 @@ func TestSyncer_SyncAny_abort(t *testing.T) {
_ , err := rts . syncer . AddSnapshot ( peerID , s )
_ , err := rts . syncer . AddSnapshot ( peerID , s )
require . NoError ( t , err )
require . NoError ( t , err )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( s ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_ABORT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_ABORT } , nil )
@ -286,15 +286,15 @@ func TestSyncer_SyncAny_reject(t *testing.T) {
_ , err = rts . syncer . AddSnapshot ( peerID , s11 )
_ , err = rts . syncer . AddSnapshot ( peerID , s11 )
require . NoError ( t , err )
require . NoError ( t , err )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s22 ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( s22 ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s12 ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( s12 ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s11 ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( s11 ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
@ -328,11 +328,11 @@ func TestSyncer_SyncAny_reject_format(t *testing.T) {
_ , err = rts . syncer . AddSnapshot ( peerID , s11 )
_ , err = rts . syncer . AddSnapshot ( peerID , s11 )
require . NoError ( t , err )
require . NoError ( t , err )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s22 ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( s22 ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT_FORMAT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT_FORMAT } , nil )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s11 ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( s11 ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_ABORT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_ABORT } , nil )
@ -377,11 +377,11 @@ func TestSyncer_SyncAny_reject_sender(t *testing.T) {
_ , err = rts . syncer . AddSnapshot ( peerCID , sbc )
_ , err = rts . syncer . AddSnapshot ( peerCID , sbc )
require . NoError ( t , err )
require . NoError ( t , err )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( sbc ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( sbc ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT_SENDER } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT_SENDER } , nil )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( sa ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( sa ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseOfferSnapshot { Result : abci . ResponseOfferSnapshot_REJECT } , nil )
@ -407,7 +407,7 @@ func TestSyncer_SyncAny_abciError(t *testing.T) {
_ , err := rts . syncer . AddSnapshot ( peerID , s )
_ , err := rts . syncer . AddSnapshot ( peerID , s )
require . NoError ( t , err )
require . NoError ( t , err )
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s ) , AppHash : [ ] byte ( "app_hash" ) ,
Snapshot : toABCI ( s ) , AppHash : [ ] byte ( "app_hash" ) ,
} ) . Once ( ) . Return ( nil , errBoom )
} ) . Once ( ) . Return ( nil , errBoom )
@ -450,7 +450,7 @@ func TestSyncer_offerSnapshot(t *testing.T) {
rts := setup ( ctx , t , nil , nil , stateProvider , 2 )
rts := setup ( ctx , t , nil , nil , stateProvider , 2 )
s := & snapshot { Height : 1 , Format : 1 , Chunks : 3 , Hash : [ ] byte { 1 , 2 , 3 } , trustedAppHash : [ ] byte ( "app_hash" ) }
s := & snapshot { Height : 1 , Format : 1 , Chunks : 3 , Hash : [ ] byte { 1 , 2 , 3 } , trustedAppHash : [ ] byte ( "app_hash" ) }
rts . conn . On ( "OfferSnapshotSync " , mock . Anything , abci . RequestOfferSnapshot {
rts . conn . On ( "OfferSnapshot" , mock . Anything , abci . RequestOfferSnapshot {
Snapshot : toABCI ( s ) ,
Snapshot : toABCI ( s ) ,
AppHash : [ ] byte ( "app_hash" ) ,
AppHash : [ ] byte ( "app_hash" ) ,
} ) . Return ( & abci . ResponseOfferSnapshot { Result : tc . result } , tc . err )
} ) . Return ( & abci . ResponseOfferSnapshot { Result : tc . result } , tc . err )
@ -511,11 +511,11 @@ func TestSyncer_applyChunks_Results(t *testing.T) {
_ , err = chunks . Add ( & chunk { Height : 1 , Format : 1 , Index : 0 , Chunk : body } )
_ , err = chunks . Add ( & chunk { Height : 1 , Format : 1 , Index : 0 , Chunk : body } )
require . NoError ( t , err )
require . NoError ( t , err )
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 0 , Chunk : body ,
Index : 0 , Chunk : body ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : tc . result } , tc . err )
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : tc . result } , tc . err )
if tc . result == abci . ResponseApplySnapshotChunk_RETRY {
if tc . result == abci . ResponseApplySnapshotChunk_RETRY {
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 0 , Chunk : body ,
Index : 0 , Chunk : body ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk {
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk {
Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
@ -578,13 +578,13 @@ func TestSyncer_applyChunks_RefetchChunks(t *testing.T) {
require . NoError ( t , err )
require . NoError ( t , err )
// The first two chunks are accepted, before the last one asks for 1 to be refetched
// The first two chunks are accepted, before the last one asks for 1 to be refetched
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 0 , Chunk : [ ] byte { 0 } ,
Index : 0 , Chunk : [ ] byte { 0 } ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 1 , Chunk : [ ] byte { 1 } ,
Index : 1 , Chunk : [ ] byte { 1 } ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 2 , Chunk : [ ] byte { 2 } ,
Index : 2 , Chunk : [ ] byte { 2 } ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk {
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk {
Result : tc . result ,
Result : tc . result ,
@ -678,13 +678,13 @@ func TestSyncer_applyChunks_RejectSenders(t *testing.T) {
require . NoError ( t , err )
require . NoError ( t , err )
// The first two chunks are accepted, before the last one asks for b sender to be rejected
// The first two chunks are accepted, before the last one asks for b sender to be rejected
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 0 , Chunk : [ ] byte { 0 } , Sender : "aa" ,
Index : 0 , Chunk : [ ] byte { 0 } , Sender : "aa" ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 1 , Chunk : [ ] byte { 1 } , Sender : "bb" ,
Index : 1 , Chunk : [ ] byte { 1 } , Sender : "bb" ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 2 , Chunk : [ ] byte { 2 } , Sender : "cc" ,
Index : 2 , Chunk : [ ] byte { 2 } , Sender : "cc" ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk {
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk {
Result : tc . result ,
Result : tc . result ,
@ -693,7 +693,7 @@ func TestSyncer_applyChunks_RejectSenders(t *testing.T) {
// On retry, the last chunk will be tried again, so we just accept it then.
// On retry, the last chunk will be tried again, so we just accept it then.
if tc . result == abci . ResponseApplySnapshotChunk_RETRY {
if tc . result == abci . ResponseApplySnapshotChunk_RETRY {
rts . conn . On ( "ApplySnapshotChunkSync " , mock . Anything , abci . RequestApplySnapshotChunk {
rts . conn . On ( "ApplySnapshotChunk" , mock . Anything , abci . RequestApplySnapshotChunk {
Index : 2 , Chunk : [ ] byte { 2 } , Sender : "cc" ,
Index : 2 , Chunk : [ ] byte { 2 } , Sender : "cc" ,
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
} ) . Once ( ) . Return ( & abci . ResponseApplySnapshotChunk { Result : abci . ResponseApplySnapshotChunk_ACCEPT } , nil )
}
}
@ -759,7 +759,7 @@ func TestSyncer_verifyApp(t *testing.T) {
rts := setup ( ctx , t , nil , nil , nil , 2 )
rts := setup ( ctx , t , nil , nil , nil , 2 )
rts . connQuery . On ( "InfoSync " , mock . Anything , proxy . RequestInfo ) . Return ( tc . response , tc . err )
rts . connQuery . On ( "Info" , mock . Anything , proxy . RequestInfo ) . Return ( tc . response , tc . err )
version , err := rts . syncer . verifyApp ( ctx , s )
version , err := rts . syncer . verifyApp ( ctx , s )
unwrapped := errors . Unwrap ( err )
unwrapped := errors . Unwrap ( err )
if unwrapped != nil {
if unwrapped != nil {