|
@ -30,7 +30,7 @@ func TestSyncer_SyncAny(t *testing.T) { |
|
|
Version: sm.Version{ |
|
|
Version: sm.Version{ |
|
|
Consensus: version.Consensus{ |
|
|
Consensus: version.Consensus{ |
|
|
Block: version.BlockProtocol, |
|
|
Block: version.BlockProtocol, |
|
|
App: 0, |
|
|
|
|
|
|
|
|
App: testAppVersion, |
|
|
}, |
|
|
}, |
|
|
Software: version.TMVersion, |
|
|
Software: version.TMVersion, |
|
|
}, |
|
|
}, |
|
@ -189,7 +189,7 @@ func TestSyncer_SyncAny(t *testing.T) { |
|
|
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("Info", mock.Anything, proxy.RequestInfo).Return(&abci.ResponseInfo{ |
|
|
connQuery.On("Info", mock.Anything, proxy.RequestInfo).Return(&abci.ResponseInfo{ |
|
|
AppVersion: 9, |
|
|
|
|
|
|
|
|
AppVersion: testAppVersion, |
|
|
LastBlockHeight: 1, |
|
|
LastBlockHeight: 1, |
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
}, nil) |
|
|
}, nil) |
|
@ -203,10 +203,7 @@ func TestSyncer_SyncAny(t *testing.T) { |
|
|
require.Equal(t, map[uint32]int{0: 1, 1: 2, 2: 1}, chunkRequests) |
|
|
require.Equal(t, map[uint32]int{0: 1, 1: 2, 2: 1}, chunkRequests) |
|
|
chunkRequestsMtx.Unlock() |
|
|
chunkRequestsMtx.Unlock() |
|
|
|
|
|
|
|
|
// The syncer should have updated the state app version from the ABCI info response.
|
|
|
|
|
|
expectState := state |
|
|
expectState := state |
|
|
expectState.Version.Consensus.App = 9 |
|
|
|
|
|
|
|
|
|
|
|
require.Equal(t, expectState, newState) |
|
|
require.Equal(t, expectState, newState) |
|
|
require.Equal(t, commit, lastCommit) |
|
|
require.Equal(t, commit, lastCommit) |
|
|
|
|
|
|
|
@ -724,6 +721,8 @@ func TestSyncer_applyChunks_RejectSenders(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestSyncer_verifyApp(t *testing.T) { |
|
|
func TestSyncer_verifyApp(t *testing.T) { |
|
|
boom := errors.New("boom") |
|
|
boom := errors.New("boom") |
|
|
|
|
|
const appVersion = 9 |
|
|
|
|
|
appVersionMismatchErr := errors.New("app version mismatch. Expected: 9, got: 2") |
|
|
s := &snapshot{Height: 3, Format: 1, Chunks: 5, Hash: []byte{1, 2, 3}, trustedAppHash: []byte("app_hash")} |
|
|
s := &snapshot{Height: 3, Format: 1, Chunks: 5, Hash: []byte{1, 2, 3}, trustedAppHash: []byte("app_hash")} |
|
|
|
|
|
|
|
|
testcases := map[string]struct { |
|
|
testcases := map[string]struct { |
|
@ -734,17 +733,22 @@ func TestSyncer_verifyApp(t *testing.T) { |
|
|
"verified": {&abci.ResponseInfo{ |
|
|
"verified": {&abci.ResponseInfo{ |
|
|
LastBlockHeight: 3, |
|
|
LastBlockHeight: 3, |
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
AppVersion: 9, |
|
|
|
|
|
|
|
|
AppVersion: appVersion, |
|
|
}, nil, nil}, |
|
|
}, nil, nil}, |
|
|
|
|
|
"invalid app version": {&abci.ResponseInfo{ |
|
|
|
|
|
LastBlockHeight: 3, |
|
|
|
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
|
|
|
AppVersion: 2, |
|
|
|
|
|
}, nil, appVersionMismatchErr}, |
|
|
"invalid height": {&abci.ResponseInfo{ |
|
|
"invalid height": {&abci.ResponseInfo{ |
|
|
LastBlockHeight: 5, |
|
|
LastBlockHeight: 5, |
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
AppVersion: 9, |
|
|
|
|
|
|
|
|
AppVersion: appVersion, |
|
|
}, nil, errVerifyFailed}, |
|
|
}, nil, errVerifyFailed}, |
|
|
"invalid hash": {&abci.ResponseInfo{ |
|
|
"invalid hash": {&abci.ResponseInfo{ |
|
|
LastBlockHeight: 3, |
|
|
LastBlockHeight: 3, |
|
|
LastBlockAppHash: []byte("xxx"), |
|
|
LastBlockAppHash: []byte("xxx"), |
|
|
AppVersion: 9, |
|
|
|
|
|
|
|
|
AppVersion: appVersion, |
|
|
}, nil, errVerifyFailed}, |
|
|
}, nil, errVerifyFailed}, |
|
|
"error": {nil, boom, boom}, |
|
|
"error": {nil, boom, boom}, |
|
|
} |
|
|
} |
|
@ -760,16 +764,12 @@ 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("Info", 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) |
|
|
|
|
|
|
|
|
err := rts.syncer.verifyApp(ctx, s, appVersion) |
|
|
unwrapped := errors.Unwrap(err) |
|
|
unwrapped := errors.Unwrap(err) |
|
|
if unwrapped != nil { |
|
|
if unwrapped != nil { |
|
|
err = unwrapped |
|
|
err = unwrapped |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
require.Equal(t, tc.expectErr, err) |
|
|
require.Equal(t, tc.expectErr, err) |
|
|
if err == nil { |
|
|
|
|
|
require.Equal(t, tc.response.AppVersion, version) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|