|
@ -238,10 +238,10 @@ func (h *Handshaker) NBlocks() int { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: retry the handshake/replay if it fails ?
|
|
|
// TODO: retry the handshake/replay if it fails ?
|
|
|
func (h *Handshaker) Handshake(ctx context.Context, proxyApp abciclient.Client) error { |
|
|
|
|
|
|
|
|
func (h *Handshaker) Handshake(ctx context.Context, appClient abciclient.Client) error { |
|
|
|
|
|
|
|
|
// Handshake is done via ABCI Info on the query conn.
|
|
|
// Handshake is done via ABCI Info on the query conn.
|
|
|
res, err := proxyApp.Info(ctx, proxy.RequestInfo) |
|
|
|
|
|
|
|
|
res, err := appClient.Info(ctx, proxy.RequestInfo) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return fmt.Errorf("error calling Info: %w", err) |
|
|
return fmt.Errorf("error calling Info: %w", err) |
|
|
} |
|
|
} |
|
@ -265,7 +265,7 @@ func (h *Handshaker) Handshake(ctx context.Context, proxyApp abciclient.Client) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Replay blocks up to the latest in the blockstore.
|
|
|
// Replay blocks up to the latest in the blockstore.
|
|
|
_, err = h.ReplayBlocks(ctx, h.initialState, appHash, blockHeight, proxyApp) |
|
|
|
|
|
|
|
|
_, err = h.ReplayBlocks(ctx, h.initialState, appHash, blockHeight, appClient) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return fmt.Errorf("error on replay: %w", err) |
|
|
return fmt.Errorf("error on replay: %w", err) |
|
|
} |
|
|
} |
|
@ -286,7 +286,7 @@ func (h *Handshaker) ReplayBlocks( |
|
|
state sm.State, |
|
|
state sm.State, |
|
|
appHash []byte, |
|
|
appHash []byte, |
|
|
appBlockHeight int64, |
|
|
appBlockHeight int64, |
|
|
proxyApp abciclient.Client, |
|
|
|
|
|
|
|
|
appClient abciclient.Client, |
|
|
) ([]byte, error) { |
|
|
) ([]byte, error) { |
|
|
storeBlockBase := h.store.Base() |
|
|
storeBlockBase := h.store.Base() |
|
|
storeBlockHeight := h.store.Height() |
|
|
storeBlockHeight := h.store.Height() |
|
@ -317,7 +317,7 @@ func (h *Handshaker) ReplayBlocks( |
|
|
Validators: nextVals, |
|
|
Validators: nextVals, |
|
|
AppStateBytes: h.genDoc.AppState, |
|
|
AppStateBytes: h.genDoc.AppState, |
|
|
} |
|
|
} |
|
|
res, err := proxyApp.InitChain(ctx, req) |
|
|
|
|
|
|
|
|
res, err := appClient.InitChain(ctx, req) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
@ -391,7 +391,7 @@ func (h *Handshaker) ReplayBlocks( |
|
|
// Either the app is asking for replay, or we're all synced up.
|
|
|
// Either the app is asking for replay, or we're all synced up.
|
|
|
if appBlockHeight < storeBlockHeight { |
|
|
if appBlockHeight < storeBlockHeight { |
|
|
// the app is behind, so replay blocks, but no need to go through WAL (state is already synced to store)
|
|
|
// the app is behind, so replay blocks, but no need to go through WAL (state is already synced to store)
|
|
|
return h.replayBlocks(ctx, state, proxyApp, appBlockHeight, storeBlockHeight, false) |
|
|
|
|
|
|
|
|
return h.replayBlocks(ctx, state, appClient, appBlockHeight, storeBlockHeight, false) |
|
|
|
|
|
|
|
|
} else if appBlockHeight == storeBlockHeight { |
|
|
} else if appBlockHeight == storeBlockHeight { |
|
|
// We're good!
|
|
|
// We're good!
|
|
@ -406,7 +406,7 @@ func (h *Handshaker) ReplayBlocks( |
|
|
case appBlockHeight < stateBlockHeight: |
|
|
case appBlockHeight < stateBlockHeight: |
|
|
// the app is further behind than it should be, so replay blocks
|
|
|
// the app is further behind than it should be, so replay blocks
|
|
|
// but leave the last block to go through the WAL
|
|
|
// but leave the last block to go through the WAL
|
|
|
return h.replayBlocks(ctx, state, proxyApp, appBlockHeight, storeBlockHeight, true) |
|
|
|
|
|
|
|
|
return h.replayBlocks(ctx, state, appClient, appBlockHeight, storeBlockHeight, true) |
|
|
|
|
|
|
|
|
case appBlockHeight == stateBlockHeight: |
|
|
case appBlockHeight == stateBlockHeight: |
|
|
// We haven't run Commit (both the state and app are one block behind),
|
|
|
// We haven't run Commit (both the state and app are one block behind),
|
|
@ -414,7 +414,7 @@ func (h *Handshaker) ReplayBlocks( |
|
|
// NOTE: We could instead use the cs.WAL on cs.Start,
|
|
|
// NOTE: We could instead use the cs.WAL on cs.Start,
|
|
|
// but we'd have to allow the WAL to replay a block that wrote it's #ENDHEIGHT
|
|
|
// but we'd have to allow the WAL to replay a block that wrote it's #ENDHEIGHT
|
|
|
h.logger.Info("Replay last block using real app") |
|
|
h.logger.Info("Replay last block using real app") |
|
|
state, err = h.replayBlock(ctx, state, storeBlockHeight, proxyApp) |
|
|
|
|
|
|
|
|
state, err = h.replayBlock(ctx, state, storeBlockHeight, appClient) |
|
|
return state.AppHash, err |
|
|
return state.AppHash, err |
|
|
|
|
|
|
|
|
case appBlockHeight == storeBlockHeight: |
|
|
case appBlockHeight == storeBlockHeight: |
|
@ -449,7 +449,7 @@ func (h *Handshaker) ReplayBlocks( |
|
|
func (h *Handshaker) replayBlocks( |
|
|
func (h *Handshaker) replayBlocks( |
|
|
ctx context.Context, |
|
|
ctx context.Context, |
|
|
state sm.State, |
|
|
state sm.State, |
|
|
proxyApp abciclient.Client, |
|
|
|
|
|
|
|
|
appClient abciclient.Client, |
|
|
appBlockHeight, |
|
|
appBlockHeight, |
|
|
storeBlockHeight int64, |
|
|
storeBlockHeight int64, |
|
|
mutateState bool) ([]byte, error) { |
|
|
mutateState bool) ([]byte, error) { |
|
@ -485,16 +485,16 @@ func (h *Handshaker) replayBlocks( |
|
|
// We emit events for the index services at the final block due to the sync issue when
|
|
|
// We emit events for the index services at the final block due to the sync issue when
|
|
|
// the node shutdown during the block committing status.
|
|
|
// the node shutdown during the block committing status.
|
|
|
blockExec := sm.NewBlockExecutor( |
|
|
blockExec := sm.NewBlockExecutor( |
|
|
h.stateStore, h.logger, proxyApp, emptyMempool{}, sm.EmptyEvidencePool{}, h.store) |
|
|
|
|
|
|
|
|
h.stateStore, h.logger, appClient, emptyMempool{}, sm.EmptyEvidencePool{}, h.store) |
|
|
blockExec.SetEventBus(h.eventBus) |
|
|
blockExec.SetEventBus(h.eventBus) |
|
|
appHash, err = sm.ExecCommitBlock(ctx, |
|
|
appHash, err = sm.ExecCommitBlock(ctx, |
|
|
blockExec, proxyApp, block, h.logger, h.stateStore, h.genDoc.InitialHeight, state) |
|
|
|
|
|
|
|
|
blockExec, appClient, block, h.logger, h.stateStore, h.genDoc.InitialHeight, state) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
appHash, err = sm.ExecCommitBlock(ctx, |
|
|
appHash, err = sm.ExecCommitBlock(ctx, |
|
|
nil, proxyApp, block, h.logger, h.stateStore, h.genDoc.InitialHeight, state) |
|
|
|
|
|
|
|
|
nil, appClient, block, h.logger, h.stateStore, h.genDoc.InitialHeight, state) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
@ -505,7 +505,7 @@ func (h *Handshaker) replayBlocks( |
|
|
|
|
|
|
|
|
if mutateState { |
|
|
if mutateState { |
|
|
// sync the final block
|
|
|
// sync the final block
|
|
|
state, err = h.replayBlock(ctx, state, storeBlockHeight, proxyApp) |
|
|
|
|
|
|
|
|
state, err = h.replayBlock(ctx, state, storeBlockHeight, appClient) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
@ -521,14 +521,14 @@ func (h *Handshaker) replayBlock( |
|
|
ctx context.Context, |
|
|
ctx context.Context, |
|
|
state sm.State, |
|
|
state sm.State, |
|
|
height int64, |
|
|
height int64, |
|
|
proxyApp abciclient.Client, |
|
|
|
|
|
|
|
|
appClient abciclient.Client, |
|
|
) (sm.State, error) { |
|
|
) (sm.State, error) { |
|
|
block := h.store.LoadBlock(height) |
|
|
block := h.store.LoadBlock(height) |
|
|
meta := h.store.LoadBlockMeta(height) |
|
|
meta := h.store.LoadBlockMeta(height) |
|
|
|
|
|
|
|
|
// Use stubs for both mempool and evidence pool since no transactions nor
|
|
|
// Use stubs for both mempool and evidence pool since no transactions nor
|
|
|
// evidence are needed here - block already exists.
|
|
|
// evidence are needed here - block already exists.
|
|
|
blockExec := sm.NewBlockExecutor(h.stateStore, h.logger, proxyApp, emptyMempool{}, sm.EmptyEvidencePool{}, h.store) |
|
|
|
|
|
|
|
|
blockExec := sm.NewBlockExecutor(h.stateStore, h.logger, appClient, emptyMempool{}, sm.EmptyEvidencePool{}, h.store) |
|
|
blockExec.SetEventBus(h.eventBus) |
|
|
blockExec.SetEventBus(h.eventBus) |
|
|
|
|
|
|
|
|
var err error |
|
|
var err error |
|
|