e2e: programmable ABCI method times (#8638)

* e2e: programmable ABCI method times

* fix linting error
This commit is contained in:
Callum Waters
2022-05-31 12:22:52 +02:00
committed by GitHub
parent 3dec4a4744
commit fefce8dc35
6 changed files with 131 additions and 61 deletions
+38
View File
@@ -13,6 +13,7 @@ import (
"strconv"
"strings"
"sync"
"time"
"github.com/tendermint/tendermint/abci/example/code"
abci "github.com/tendermint/tendermint/abci/types"
@@ -80,6 +81,14 @@ type Config struct {
//
// height <-> pubkey <-> voting power
ValidatorUpdates map[string]map[string]uint8 `toml:"validator_update"`
// Add artificial delays to each of the main ABCI calls to mimic computation time
// of the application
PrepareProposalDelayMS uint64 `toml:"prepare_proposal_delay_ms"`
ProcessProposalDelayMS uint64 `toml:"process_proposal_delay_ms"`
CheckTxDelayMS uint64 `toml:"check_tx_delay_ms"`
VoteExtensionDelayMS uint64 `toml:"vote_extension_delay_ms"`
FinalizeBlockDelayMS uint64 `toml:"finalize_block_delay_ms"`
}
func DefaultConfig(dir string) *Config {
@@ -164,6 +173,11 @@ func (app *Application) CheckTx(_ context.Context, req *abci.RequestCheckTx) (*a
Code: code.CodeTypeEncodingError,
}, nil
}
if app.cfg.CheckTxDelayMS != 0 {
time.Sleep(time.Duration(app.cfg.CheckTxDelayMS) * time.Millisecond)
}
return &abci.ResponseCheckTx{Code: code.CodeTypeOK, GasWanted: 1}, nil
}
@@ -189,6 +203,10 @@ func (app *Application) FinalizeBlock(_ context.Context, req *abci.RequestFinali
panic(err)
}
if app.cfg.FinalizeBlockDelayMS != 0 {
time.Sleep(time.Duration(app.cfg.FinalizeBlockDelayMS) * time.Millisecond)
}
return &abci.ResponseFinalizeBlock{
TxResults: txs,
ValidatorUpdates: valUpdates,
@@ -394,6 +412,11 @@ func (app *Application) PrepareProposal(_ context.Context, req *abci.RequestPrep
Tx: tx,
})
}
if app.cfg.PrepareProposalDelayMS != 0 {
time.Sleep(time.Duration(app.cfg.PrepareProposalDelayMS) * time.Millisecond)
}
return &abci.ResponsePrepareProposal{TxRecords: trs}, nil
}
@@ -415,6 +438,11 @@ func (app *Application) ProcessProposal(_ context.Context, req *abci.RequestProc
}
}
}
if app.cfg.ProcessProposalDelayMS != 0 {
time.Sleep(time.Duration(app.cfg.ProcessProposalDelayMS) * time.Millisecond)
}
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil
}
@@ -442,6 +470,11 @@ func (app *Application) ExtendVote(_ context.Context, req *abci.RequestExtendVot
// nolint:gosec // G404: Use of weak random number generator
num := rand.Int63n(voteExtensionMaxVal)
extLen := binary.PutVarint(ext, num)
if app.cfg.VoteExtensionDelayMS != 0 {
time.Sleep(time.Duration(app.cfg.VoteExtensionDelayMS) * time.Millisecond)
}
app.logger.Info("generated vote extension", "num", num, "ext", fmt.Sprintf("%x", ext[:extLen]), "state.Height", app.state.Height)
return &abci.ResponseExtendVote{
VoteExtension: ext[:extLen],
@@ -476,6 +509,11 @@ func (app *Application) VerifyVoteExtension(_ context.Context, req *abci.Request
Status: abci.ResponseVerifyVoteExtension_REJECT,
}, nil
}
if app.cfg.VoteExtensionDelayMS != 0 {
time.Sleep(time.Duration(app.cfg.VoteExtensionDelayMS) * time.Millisecond)
}
app.logger.Info("verified vote extension value", "req", req, "num", num)
return &abci.ResponseVerifyVoteExtension{
Status: abci.ResponseVerifyVoteExtension_ACCEPT,