mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-22 07:06:14 +00:00
clean up usage of begin block, deliver tx and end block
This commit is contained in:
@@ -77,4 +77,4 @@ func TestGRPC(t *testing.T) {
|
||||
|
||||
func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return tmnet.Connect(addr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestHangingAsyncCalls(t *testing.T) {
|
||||
|
||||
resp := make(chan error, 1)
|
||||
go func() {
|
||||
// Start BeginBlock and flush it
|
||||
// Call CheckTx
|
||||
reqres, err := c.CheckTxAsync(context.Background(), &types.RequestCheckTx{})
|
||||
require.NoError(t, err)
|
||||
// wait 20 ms for all events to travel socket, but
|
||||
@@ -60,7 +60,7 @@ func TestHangingAsyncCalls(t *testing.T) {
|
||||
err = s.Stop()
|
||||
require.NoError(t, err)
|
||||
|
||||
// wait for the response from BeginBlock
|
||||
// wait for the response from CheckTx
|
||||
reqres.Wait()
|
||||
fmt.Print(reqres)
|
||||
resp <- c.Error()
|
||||
@@ -94,7 +94,7 @@ func TestBulk(t *testing.T) {
|
||||
|
||||
// Connect to the socket
|
||||
client := abcicli.NewSocketClient(socket, false)
|
||||
|
||||
|
||||
t.Cleanup(func() {
|
||||
if err := client.Stop(); err != nil {
|
||||
t.Log(err)
|
||||
@@ -122,7 +122,6 @@ func TestBulk(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
func setupClientServer(t *testing.T, app types.Application) (
|
||||
service.Service, abcicli.Client) {
|
||||
t.Helper()
|
||||
|
||||
@@ -41,7 +41,7 @@ reindex from the base block height(inclusive); and the default end-height is 0,
|
||||
the tooling will reindex until the latest block height(inclusive). User can omit
|
||||
either or both arguments.
|
||||
|
||||
Note: This operation requires ABCI Responses. Do not set DiscardFinalizeBlockResponses to true if you
|
||||
Note: This operation requires ABCI Responses. Do not set DiscardABCIResponses to true if you
|
||||
want to use this command.
|
||||
`,
|
||||
Example: `
|
||||
|
||||
@@ -90,7 +90,7 @@ func loadStateAndBlockStore(config *cfg.Config) (*store.BlockStore, state.Store,
|
||||
return nil, nil, err
|
||||
}
|
||||
stateStore := state.NewStore(stateDB, state.StoreOptions{
|
||||
DiscardFinalizeBlockResponses: config.Storage.DiscardFinalizeBlockResponses,
|
||||
DiscardABCIResponses: config.Storage.DiscardABCIResponses,
|
||||
})
|
||||
|
||||
return blockStore, stateStore, nil
|
||||
|
||||
@@ -359,7 +359,7 @@ func TestRecoverPendingEvidence(t *testing.T) {
|
||||
func initializeStateFromValidatorSet(valSet *types.ValidatorSet, height int64) sm.Store {
|
||||
stateDB := dbm.NewMemDB()
|
||||
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
|
||||
DiscardFinalizeBlockResponses: false,
|
||||
DiscardABCIResponses: false,
|
||||
})
|
||||
state := sm.State{
|
||||
ChainID: evidenceChainID,
|
||||
|
||||
@@ -98,11 +98,11 @@ func TestReactorConcurrency(t *testing.T) {
|
||||
reactors[0].mempool.Lock()
|
||||
defer reactors[0].mempool.Unlock()
|
||||
|
||||
deliverTxResponses := make([]*abci.ExecTxResult, len(txs))
|
||||
txResponses := make([]*abci.ExecTxResult, len(txs))
|
||||
for i := range txs {
|
||||
deliverTxResponses[i] = &abci.ExecTxResult{Code: 0}
|
||||
txResponses[i] = &abci.ExecTxResult{Code: 0}
|
||||
}
|
||||
err := reactors[0].mempool.Update(1, txs, deliverTxResponses, nil, nil)
|
||||
err := reactors[0].mempool.Update(1, txs, txResponses, nil, nil)
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
|
||||
@@ -387,7 +387,7 @@ func (txmp *TxMempool) Update(
|
||||
) error {
|
||||
// Safety check: Transactions and responses must match in number.
|
||||
if len(blockTxs) != len(txResults) {
|
||||
panic(fmt.Sprintf("mempool: got %d transactions but %d DeliverTx responses",
|
||||
panic(fmt.Sprintf("mempool: got %d transactions but %d TxResult responses",
|
||||
len(blockTxs), len(txResults)))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ func NewNode(config *cfg.Config,
|
||||
// EventBus and IndexerService must be started before the handshake because
|
||||
// we might need to index the txs of the replayed block as this might not have happened
|
||||
// when the node stopped last time (i.e. the node stopped after it saved the block
|
||||
// but before it indexed the txs, or, endblocker panicked)
|
||||
// but before it indexed the txs)
|
||||
eventBus, err := createAndStartEventBus(logger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -74,7 +74,7 @@ type SignClient interface {
|
||||
Tx(ctx context.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)
|
||||
|
||||
// TxSearch defines a method to search for a paginated set of transactions by
|
||||
// DeliverTx event search criteria.
|
||||
// transaction event search criteria.
|
||||
TxSearch(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
@@ -83,8 +83,8 @@ type SignClient interface {
|
||||
orderBy string,
|
||||
) (*ctypes.ResultTxSearch, error)
|
||||
|
||||
// BlockSearch defines a method to search for a paginated set of blocks by
|
||||
// BeginBlock and EndBlock event search criteria.
|
||||
// BlockSearch defines a method to search for a paginated set of blocks based
|
||||
// from FinalizeBlock event search criteria.
|
||||
BlockSearch(
|
||||
ctx context.Context,
|
||||
query string,
|
||||
|
||||
+2
-2
@@ -191,8 +191,8 @@ func BlockResults(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlockR
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BlockSearch searches for a paginated set of blocks matching BeginBlock and
|
||||
// EndBlock event search criteria.
|
||||
// BlockSearch searches for a paginated set of blocks matching
|
||||
// FinalizeBlock event search criteria.
|
||||
func BlockSearch(
|
||||
ctx *rpctypes.Context,
|
||||
query string,
|
||||
|
||||
+9
-9
@@ -17,7 +17,7 @@ import (
|
||||
// NOTE: tx should be signed, but this is only checked at the app level (not by Tendermint!)
|
||||
|
||||
// BroadcastTxAsync returns right away, with no response. Does not wait for
|
||||
// CheckTx nor DeliverTx results.
|
||||
// CheckTx nor transcation results.
|
||||
// More: https://docs.tendermint.com/main/rpc/#/Tx/broadcast_tx_async
|
||||
func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
err := env.Mempool.CheckTx(tx, nil, mempl.TxInfo{})
|
||||
@@ -29,7 +29,7 @@ func BroadcastTxAsync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadca
|
||||
}
|
||||
|
||||
// BroadcastTxSync returns with the response from CheckTx. Does not wait for
|
||||
// DeliverTx result.
|
||||
// the transaction result.
|
||||
// More: https://docs.tendermint.com/main/rpc/#/Tx/broadcast_tx_sync
|
||||
func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
|
||||
resCh := make(chan *abci.ResponseCheckTx, 1)
|
||||
@@ -58,7 +58,7 @@ func BroadcastTxSync(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcas
|
||||
}
|
||||
}
|
||||
|
||||
// BroadcastTxCommit returns with the responses from CheckTx and DeliverTx.
|
||||
// BroadcastTxCommit returns with the responses from CheckTx and ExecTxResult.
|
||||
// More: https://docs.tendermint.com/main/rpc/#/Tx/broadcast_tx_commit
|
||||
func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||
subscriber := ctx.RemoteAddr()
|
||||
@@ -73,7 +73,7 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc
|
||||
subCtx, cancel := context.WithTimeout(ctx.Context(), SubscribeTimeout)
|
||||
defer cancel()
|
||||
q := types.EventQueryTxFor(tx)
|
||||
deliverTxSub, err := env.EventBus.Subscribe(subCtx, subscriber, q)
|
||||
txSub, err := env.EventBus.Subscribe(subCtx, subscriber, q)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to subscribe to tx: %w", err)
|
||||
env.Logger.Error("Error on broadcast_tx_commit", "err", err)
|
||||
@@ -111,7 +111,7 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc
|
||||
|
||||
// Wait for the tx to be included in a block or timeout.
|
||||
select {
|
||||
case msg := <-deliverTxSub.Out(): // The tx was included in a block.
|
||||
case msg := <-txSub.Out(): // The tx was included in a block.
|
||||
txResultEvent := msg.Data().(types.EventDataTx)
|
||||
return &ctypes.ResultBroadcastTxCommit{
|
||||
CheckTx: *checkTxRes,
|
||||
@@ -119,14 +119,14 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc
|
||||
Hash: tx.Hash(),
|
||||
Height: txResultEvent.Height,
|
||||
}, nil
|
||||
case <-deliverTxSub.Cancelled():
|
||||
case <-txSub.Cancelled():
|
||||
var reason string
|
||||
if deliverTxSub.Err() == nil {
|
||||
if txSub.Err() == nil {
|
||||
reason = "Tendermint exited"
|
||||
} else {
|
||||
reason = deliverTxSub.Err().Error()
|
||||
reason = txSub.Err().Error()
|
||||
}
|
||||
err = fmt.Errorf("deliverTxSub was canceled (reason: %s)", reason)
|
||||
err = fmt.Errorf("txSub was canceled (reason: %s)", reason)
|
||||
env.Logger.Error("Error on broadcastTxCommit", "err", err)
|
||||
return &ctypes.ResultBroadcastTxCommit{
|
||||
CheckTx: *checkTxRes,
|
||||
|
||||
@@ -181,7 +181,7 @@ type ResultBroadcastTx struct {
|
||||
Hash bytes.HexBytes `json:"hash"`
|
||||
}
|
||||
|
||||
// CheckTx and DeliverTx results
|
||||
// CheckTx and ExecTx results
|
||||
type ResultBroadcastTxCommit struct {
|
||||
CheckTx abci.ResponseCheckTx `json:"check_tx"`
|
||||
TxResult abci.ExecTxResult `json:"tx_result"`
|
||||
|
||||
@@ -15,10 +15,10 @@ type BlockIndexer interface {
|
||||
// upon database query failure.
|
||||
Has(height int64) (bool, error)
|
||||
|
||||
// Index indexes BeginBlock and EndBlock events for a given block by its height.
|
||||
// Index indexes FinalizeBlock events for a given block by its height.
|
||||
Index(types.EventDataNewBlockEvents) error
|
||||
|
||||
// Search performs a query for block heights that match a given BeginBlock
|
||||
// and Endblock event search criteria.
|
||||
// Search performs a query for block heights that match a given FinalizeBlock
|
||||
// event search criteria.
|
||||
Search(ctx context.Context, q *query.Query) ([]int64, error)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
var _ indexer.BlockIndexer = (*BlockerIndexer)(nil)
|
||||
|
||||
// BlockerIndexer implements a block indexer, indexing BeginBlock and EndBlock
|
||||
// BlockerIndexer implements a block indexer, indexing FinalizeBlock
|
||||
// events with an underlying KV store. Block events are indexed by their height,
|
||||
// such that matching search criteria returns the respective block height(s).
|
||||
type BlockerIndexer struct {
|
||||
@@ -44,12 +44,11 @@ func (idx *BlockerIndexer) Has(height int64) (bool, error) {
|
||||
return idx.store.Has(key)
|
||||
}
|
||||
|
||||
// Index indexes BeginBlock and EndBlock events for a given block by its height.
|
||||
// Index indexes FinalizeBlock events for a given block by its height.
|
||||
// The following is indexed:
|
||||
//
|
||||
// primary key: encode(block.height | height) => encode(height)
|
||||
// BeginBlock events: encode(eventType.eventAttr|eventValue|height|begin_block) => encode(height)
|
||||
// EndBlock events: encode(eventType.eventAttr|eventValue|height|end_block) => encode(height)
|
||||
// FinalizeBlock events: encode(eventType.eventAttr|eventValue|height|finalize_block) => encode(height)
|
||||
func (idx *BlockerIndexer) Index(bh types.EventDataNewBlockEvents) error {
|
||||
batch := idx.store.NewBatch()
|
||||
defer batch.Close()
|
||||
@@ -66,15 +65,15 @@ func (idx *BlockerIndexer) Index(bh types.EventDataNewBlockEvents) error {
|
||||
}
|
||||
|
||||
// 2. index block events
|
||||
if err := idx.indexEvents(batch, bh.Events, "begin_block", height); err != nil {
|
||||
return fmt.Errorf("failed to index BeginBlock events: %w", err)
|
||||
if err := idx.indexEvents(batch, bh.Events, "finalize_block", height); err != nil {
|
||||
return fmt.Errorf("failed to index FinalizeBlock events: %w", err)
|
||||
}
|
||||
|
||||
return batch.WriteSync()
|
||||
}
|
||||
|
||||
// Search performs a query for block heights that match a given BeginBlock
|
||||
// and Endblock event search criteria. The given query can match against zero,
|
||||
// Search performs a query for block heights that match a given FinalizeBlock
|
||||
// event search criteria. The given query can match against zero,
|
||||
// one or more block heights. In the case of height queries, i.e. block.height=H,
|
||||
// if the height is indexed, that height alone will be returned. An error and
|
||||
// nil slice is returned. Otherwise, a non-nil slice and nil error is returned.
|
||||
|
||||
@@ -24,8 +24,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
eventTypeBeginBlock = "begin_block"
|
||||
eventTypeEndBlock = "end_block"
|
||||
eventTypeFinalizeBlock = "finaliz_block"
|
||||
)
|
||||
|
||||
// TxIndexer returns a bridge from es to the Tendermint v0.34 transaction indexer.
|
||||
|
||||
@@ -165,7 +165,7 @@ INSERT INTO `+tableBlocks+` (height, chain_id, created_at)
|
||||
}
|
||||
// Insert all the block events. Order is important here,
|
||||
if err := insertEvents(dbtx, blockID, 0, h.Events); err != nil {
|
||||
return fmt.Errorf("begin-block events: %w", err)
|
||||
return fmt.Errorf("finalizeblock events: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -351,17 +351,8 @@ SELECT height FROM `+tableBlocks+` WHERE height = $1;
|
||||
if err := testDB().QueryRow(`
|
||||
SELECT type, height, chain_id FROM `+viewBlockEvents+`
|
||||
WHERE height = $1 AND type = $2 AND chain_id = $3;
|
||||
`, height, eventTypeBeginBlock, chainID).Err(); err == sql.ErrNoRows {
|
||||
t.Errorf("No %q event found for height=%d", eventTypeBeginBlock, height)
|
||||
} else if err != nil {
|
||||
t.Fatalf("Database query failed: %v", err)
|
||||
}
|
||||
|
||||
if err := testDB().QueryRow(`
|
||||
SELECT type, height, chain_id FROM `+viewBlockEvents+`
|
||||
WHERE height = $1 AND type = $2 AND chain_id = $3;
|
||||
`, height, eventTypeEndBlock, chainID).Err(); err == sql.ErrNoRows {
|
||||
t.Errorf("No %q event found for height=%d", eventTypeEndBlock, height)
|
||||
`, height, eventTypeFinalizeBlock, chainID).Err(); err == sql.ErrNoRows {
|
||||
t.Errorf("No %q event found for height=%d", eventTypeFinalizeBlock, height)
|
||||
} else if err != nil {
|
||||
t.Fatalf("Database query failed: %v", err)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "block_processing_time",
|
||||
Help: "Time between BeginBlock and EndBlock in ms.",
|
||||
Help: "Time spent processig finalize block.",
|
||||
|
||||
Buckets: stdprometheus.LinearBuckets(1, 10, 10),
|
||||
}, labels).With(labelsAndValues...),
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ const (
|
||||
|
||||
// Metrics contains metrics exposed by this package.
|
||||
type Metrics struct {
|
||||
// Time between BeginBlock and EndBlock in ms.
|
||||
// Time spent processing FinalizeBlock
|
||||
BlockProcessingTime metrics.Histogram `metrics_buckettype:"lin" metrics_bucketsizes:"1, 10, 10"`
|
||||
|
||||
// ConsensusParamUpdates is the total number of times the application has
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ type State struct {
|
||||
LastHeightValidatorsChanged int64
|
||||
|
||||
// Consensus parameters used for validating blocks.
|
||||
// Changes returned by EndBlock and updated after Commit.
|
||||
// Changes returned by FinalizeBlock and updated after Commit.
|
||||
ConsensusParams types.ConsensusParams
|
||||
LastHeightConsensusParamsChanged int64
|
||||
|
||||
|
||||
+2
-2
@@ -214,11 +214,11 @@ func TestTxResultsHash(t *testing.T) {
|
||||
|
||||
root := sm.TxResultsHash(txResults)
|
||||
|
||||
// root should be Merkle tree root of DeliverTxs responses
|
||||
// root should be Merkle tree root of ExecTxResult responses
|
||||
results := types.NewResults(txResults)
|
||||
assert.Equal(t, root, results.Hash())
|
||||
|
||||
// test we can prove first DeliverTx
|
||||
// test we can prove first ExecTxResult
|
||||
proof := results.ProveResult(0)
|
||||
bz, err := results[0].Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
+1
-1
@@ -342,7 +342,7 @@ type Header struct {
|
||||
ConsensusHash tmbytes.HexBytes `json:"consensus_hash"` // consensus params for current block
|
||||
AppHash tmbytes.HexBytes `json:"app_hash"` // state after txs from the previous block
|
||||
// root hash of all results from the txs from the previous block
|
||||
// see `deterministicResponseDeliverTx` to understand which parts of a tx is hashed into here
|
||||
// see `deterministicExecTxResult` to understand which parts of a tx is hashed into here
|
||||
LastResultsHash tmbytes.HexBytes `json:"last_results_hash"`
|
||||
|
||||
// consensus info
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ func shouldBatchVerify(vals *ValidatorSet, commit *Commit) bool {
|
||||
//
|
||||
// It checks all the signatures! While it's safe to exit as soon as we have
|
||||
// 2/3+ signatures, doing so would impact incentivization logic in the ABCI
|
||||
// application that depends on the LastCommitInfo sent in BeginBlock, which
|
||||
// application that depends on the LastCommitInfo sent in FinalizeBlock, which
|
||||
// includes which validators signed. For instance, Gaia incentivizes proposers
|
||||
// with a bonus for including more than +2/3 of the signatures.
|
||||
func VerifyCommit(chainID string, vals *ValidatorSet, blockID BlockID,
|
||||
|
||||
Reference in New Issue
Block a user