|
@ -748,6 +748,9 @@ func testHandshakeReplay( |
|
|
filepath.Join(cfg.DBDir(), fmt.Sprintf("replay_test_%d_%d_a_r%d", nBlocks, mode, rand.Int()))) |
|
|
filepath.Join(cfg.DBDir(), fmt.Sprintf("replay_test_%d_%d_a_r%d", nBlocks, mode, rand.Int()))) |
|
|
t.Cleanup(func() { require.NoError(t, kvstoreApp.Close()) }) |
|
|
t.Cleanup(func() { require.NoError(t, kvstoreApp.Close()) }) |
|
|
|
|
|
|
|
|
|
|
|
eventBus := eventbus.NewDefault(logger) |
|
|
|
|
|
require.NoError(t, eventBus.Start(ctx)) |
|
|
|
|
|
|
|
|
clientCreator2 := abciclient.NewLocalClient(logger, kvstoreApp) |
|
|
clientCreator2 := abciclient.NewLocalClient(logger, kvstoreApp) |
|
|
if nBlocks > 0 { |
|
|
if nBlocks > 0 { |
|
|
// run nBlocks against a new client to build up the app state.
|
|
|
// run nBlocks against a new client to build up the app state.
|
|
@ -757,7 +760,7 @@ func testHandshakeReplay( |
|
|
stateStore := sm.NewStore(stateDB1) |
|
|
stateStore := sm.NewStore(stateDB1) |
|
|
err := stateStore.Save(genesisState) |
|
|
err := stateStore.Save(genesisState) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
buildAppStateFromChain(ctx, t, proxyApp, stateStore, sim.Mempool, sim.Evpool, genesisState, chain, nBlocks, mode, store) |
|
|
|
|
|
|
|
|
buildAppStateFromChain(ctx, t, proxyApp, stateStore, sim.Mempool, sim.Evpool, genesisState, chain, eventBus, nBlocks, mode, store) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Prune block store if requested
|
|
|
// Prune block store if requested
|
|
@ -772,7 +775,7 @@ func testHandshakeReplay( |
|
|
// now start the app using the handshake - it should sync
|
|
|
// now start the app using the handshake - it should sync
|
|
|
genDoc, err := sm.MakeGenesisDocFromFile(cfg.GenesisFile()) |
|
|
genDoc, err := sm.MakeGenesisDocFromFile(cfg.GenesisFile()) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
handshaker := NewHandshaker(logger, stateStore, state, store, eventbus.NopEventBus{}, genDoc) |
|
|
|
|
|
|
|
|
handshaker := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc) |
|
|
proxyApp := proxy.New(clientCreator2, logger, proxy.NopMetrics()) |
|
|
proxyApp := proxy.New(clientCreator2, logger, proxy.NopMetrics()) |
|
|
require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections") |
|
|
require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections") |
|
|
require.True(t, proxyApp.IsRunning()) |
|
|
require.True(t, proxyApp.IsRunning()) |
|
@ -822,9 +825,10 @@ func applyBlock( |
|
|
blk *types.Block, |
|
|
blk *types.Block, |
|
|
appClient abciclient.Client, |
|
|
appClient abciclient.Client, |
|
|
blockStore *mockBlockStore, |
|
|
blockStore *mockBlockStore, |
|
|
|
|
|
eventBus *eventbus.EventBus, |
|
|
) sm.State { |
|
|
) sm.State { |
|
|
testPartSize := types.BlockPartSizeBytes |
|
|
testPartSize := types.BlockPartSizeBytes |
|
|
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), appClient, mempool, evpool, blockStore) |
|
|
|
|
|
|
|
|
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), appClient, mempool, evpool, blockStore, eventBus) |
|
|
|
|
|
|
|
|
bps, err := blk.MakePartSet(testPartSize) |
|
|
bps, err := blk.MakePartSet(testPartSize) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
@ -843,6 +847,7 @@ func buildAppStateFromChain( |
|
|
evpool sm.EvidencePool, |
|
|
evpool sm.EvidencePool, |
|
|
state sm.State, |
|
|
state sm.State, |
|
|
chain []*types.Block, |
|
|
chain []*types.Block, |
|
|
|
|
|
eventBus *eventbus.EventBus, |
|
|
nBlocks int, |
|
|
nBlocks int, |
|
|
mode uint, |
|
|
mode uint, |
|
|
blockStore *mockBlockStore, |
|
|
blockStore *mockBlockStore, |
|
@ -864,18 +869,18 @@ func buildAppStateFromChain( |
|
|
case 0: |
|
|
case 0: |
|
|
for i := 0; i < nBlocks; i++ { |
|
|
for i := 0; i < nBlocks; i++ { |
|
|
block := chain[i] |
|
|
block := chain[i] |
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, appClient, blockStore) |
|
|
|
|
|
|
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, appClient, blockStore, eventBus) |
|
|
} |
|
|
} |
|
|
case 1, 2, 3: |
|
|
case 1, 2, 3: |
|
|
for i := 0; i < nBlocks-1; i++ { |
|
|
for i := 0; i < nBlocks-1; i++ { |
|
|
block := chain[i] |
|
|
block := chain[i] |
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, appClient, blockStore) |
|
|
|
|
|
|
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, appClient, blockStore, eventBus) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if mode == 2 || mode == 3 { |
|
|
if mode == 2 || mode == 3 { |
|
|
// update the kvstore height and apphash
|
|
|
// update the kvstore height and apphash
|
|
|
// as if we ran commit but not
|
|
|
// as if we ran commit but not
|
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, chain[nBlocks-1], appClient, blockStore) |
|
|
|
|
|
|
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, chain[nBlocks-1], appClient, blockStore, eventBus) |
|
|
} |
|
|
} |
|
|
default: |
|
|
default: |
|
|
require.Fail(t, "unknown mode %v", mode) |
|
|
require.Fail(t, "unknown mode %v", mode) |
|
@ -917,23 +922,26 @@ func buildTMStateFromChain( |
|
|
|
|
|
|
|
|
require.NoError(t, stateStore.Save(state)) |
|
|
require.NoError(t, stateStore.Save(state)) |
|
|
|
|
|
|
|
|
|
|
|
eventBus := eventbus.NewDefault(logger) |
|
|
|
|
|
require.NoError(t, eventBus.Start(ctx)) |
|
|
|
|
|
|
|
|
switch mode { |
|
|
switch mode { |
|
|
case 0: |
|
|
case 0: |
|
|
// sync right up
|
|
|
// sync right up
|
|
|
for _, block := range chain { |
|
|
for _, block := range chain { |
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, proxyApp, blockStore) |
|
|
|
|
|
|
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, proxyApp, blockStore, eventBus) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
case 1, 2, 3: |
|
|
case 1, 2, 3: |
|
|
// sync up to the penultimate as if we stored the block.
|
|
|
// sync up to the penultimate as if we stored the block.
|
|
|
// whether we commit or not depends on the appHash
|
|
|
// whether we commit or not depends on the appHash
|
|
|
for _, block := range chain[:len(chain)-1] { |
|
|
for _, block := range chain[:len(chain)-1] { |
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, proxyApp, blockStore) |
|
|
|
|
|
|
|
|
state = applyBlock(ctx, t, stateStore, mempool, evpool, state, block, proxyApp, blockStore, eventBus) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// apply the final block to a state copy so we can
|
|
|
// apply the final block to a state copy so we can
|
|
|
// get the right next appHash but keep the state back
|
|
|
// get the right next appHash but keep the state back
|
|
|
applyBlock(ctx, t, stateStore, mempool, evpool, state, chain[len(chain)-1], proxyApp, blockStore) |
|
|
|
|
|
|
|
|
applyBlock(ctx, t, stateStore, mempool, evpool, state, chain[len(chain)-1], proxyApp, blockStore, eventBus) |
|
|
default: |
|
|
default: |
|
|
require.Fail(t, "unknown mode %v", mode) |
|
|
require.Fail(t, "unknown mode %v", mode) |
|
|
} |
|
|
} |
|
@ -970,6 +978,9 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) { |
|
|
|
|
|
|
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
|
|
|
|
|
|
|
|
|
eventBus := eventbus.NewDefault(logger) |
|
|
|
|
|
require.NoError(t, eventBus.Start(ctx)) |
|
|
|
|
|
|
|
|
// 2. Tendermint must panic if app returns wrong hash for the first block
|
|
|
// 2. Tendermint must panic if app returns wrong hash for the first block
|
|
|
// - RANDOM HASH
|
|
|
// - RANDOM HASH
|
|
|
// - 0x02
|
|
|
// - 0x02
|
|
@ -983,7 +994,7 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) { |
|
|
t.Cleanup(func() { cancel(); proxyApp.Wait() }) |
|
|
t.Cleanup(func() { cancel(); proxyApp.Wait() }) |
|
|
|
|
|
|
|
|
assert.Panics(t, func() { |
|
|
assert.Panics(t, func() { |
|
|
h := NewHandshaker(logger, stateStore, state, store, eventbus.NopEventBus{}, genDoc) |
|
|
|
|
|
|
|
|
h := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc) |
|
|
if err = h.Handshake(ctx, proxyApp); err != nil { |
|
|
if err = h.Handshake(ctx, proxyApp); err != nil { |
|
|
t.Log(err) |
|
|
t.Log(err) |
|
|
} |
|
|
} |
|
@ -1003,7 +1014,7 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) { |
|
|
t.Cleanup(func() { cancel(); proxyApp.Wait() }) |
|
|
t.Cleanup(func() { cancel(); proxyApp.Wait() }) |
|
|
|
|
|
|
|
|
assert.Panics(t, func() { |
|
|
assert.Panics(t, func() { |
|
|
h := NewHandshaker(logger, stateStore, state, store, eventbus.NopEventBus{}, genDoc) |
|
|
|
|
|
|
|
|
h := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc) |
|
|
if err = h.Handshake(ctx, proxyApp); err != nil { |
|
|
if err = h.Handshake(ctx, proxyApp); err != nil { |
|
|
t.Log(err) |
|
|
t.Log(err) |
|
|
} |
|
|
} |
|
@ -1235,6 +1246,9 @@ func TestHandshakeUpdatesValidators(t *testing.T) { |
|
|
app := &initChainApp{vals: types.TM2PB.ValidatorUpdates(vals)} |
|
|
app := &initChainApp{vals: types.TM2PB.ValidatorUpdates(vals)} |
|
|
client := abciclient.NewLocalClient(logger, app) |
|
|
client := abciclient.NewLocalClient(logger, app) |
|
|
|
|
|
|
|
|
|
|
|
eventBus := eventbus.NewDefault(logger) |
|
|
|
|
|
require.NoError(t, eventBus.Start(ctx)) |
|
|
|
|
|
|
|
|
cfg, err := ResetConfig(t.TempDir(), "handshake_test_") |
|
|
cfg, err := ResetConfig(t.TempDir(), "handshake_test_") |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
t.Cleanup(func() { _ = os.RemoveAll(cfg.RootDir) }) |
|
|
t.Cleanup(func() { _ = os.RemoveAll(cfg.RootDir) }) |
|
@ -1252,7 +1266,7 @@ func TestHandshakeUpdatesValidators(t *testing.T) { |
|
|
genDoc, err := sm.MakeGenesisDocFromFile(cfg.GenesisFile()) |
|
|
genDoc, err := sm.MakeGenesisDocFromFile(cfg.GenesisFile()) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
handshaker := NewHandshaker(logger, stateStore, state, store, eventbus.NopEventBus{}, genDoc) |
|
|
|
|
|
|
|
|
handshaker := NewHandshaker(logger, stateStore, state, store, eventBus, genDoc) |
|
|
proxyApp := proxy.New(client, logger, proxy.NopMetrics()) |
|
|
proxyApp := proxy.New(client, logger, proxy.NopMetrics()) |
|
|
require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections") |
|
|
require.NoError(t, proxyApp.Start(ctx), "Error starting proxy app connections") |
|
|
|
|
|
|
|
|