Skip to content

Commit

Permalink
Backport of sam/abci-responses (tendermint#9090) (tendermint#9159)
Browse files Browse the repository at this point in the history
*backport of sam/abci-responses

Co-authored-by: William Banfield <[email protected]>
  • Loading branch information
samricotta and williambanfield authored Aug 11, 2022
1 parent 65367d7 commit fbd754b
Show file tree
Hide file tree
Showing 114 changed files with 1,132 additions and 581 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ linters-settings:
# check-shadowing: true
revive:
min-confidence: 0
maligned:
suggest-new: true
misspell:
locale: US
ignore-words:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi

### IMPROVEMENTS

- [config] \#9054 Flag added to overwrite abciresponses.

### BUG FIXES

- [#9103] fix unsafe-reset-all for working with home path (@rootwarp)
5 changes: 2 additions & 3 deletions abci/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
Package server is used to start a new ABCI server.
It contains two server implementation:
* gRPC server
* socket server
- gRPC server
- socket server
*/
package server

Expand Down
31 changes: 15 additions & 16 deletions behaviour/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@ There are four different behaviours a reactor can report.
1. bad message
type badMessage struct {
explanation string
}
type badMessage struct {
explanation string
}
This message will request the peer be stopped for an error
# This message will request the peer be stopped for an error
2. message out of order
type messageOutOfOrder struct {
explanation string
}
type messageOutOfOrder struct {
explanation string
}
This message will request the peer be stopped for an error
# This message will request the peer be stopped for an error
3. consesnsus Vote
type consensusVote struct {
explanation string
}
type consensusVote struct {
explanation string
}
This message will request the peer be marked as good
# This message will request the peer be marked as good
4. block part
type blockPart struct {
explanation string
}
type blockPart struct {
explanation string
}
This message will request the peer be marked as good
*/
package behaviour
1 change: 1 addition & 0 deletions blockchain/v0/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ func (pool *BlockPool) sendError(err error, peerID p2p.ID) {
}

// for debugging purposes
//
//nolint:unused
func (pool *BlockPool) debug() string {
pool.mtx.Lock()
Expand Down
8 changes: 6 additions & 2 deletions blockchain/v0/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func newBlockchainReactor(

blockDB := dbm.NewMemDB()
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
blockStore := store.NewBlockStore(blockDB)

state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
Expand All @@ -83,7 +85,9 @@ func newBlockchainReactor(
// pool.height is determined from the store.
fastSync := true
db := dbm.NewMemDB()
stateStore = sm.NewStore(db)
stateStore = sm.NewStore(db, sm.StoreOptions{
DiscardABCIResponses: false,
})
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
if err = stateStore.Save(state); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions blockchain/v1/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ func (bcR *BlockchainReactor) switchToConsensus() {
// Called by FSM and pool:
// - pool calls when it detects slow peer or when peer times out
// - FSM calls when:
// - adding a block (addBlock) fails
// - reactor processing of a block reports failure and FSM sends back the peers of first and second blocks
// - adding a block (addBlock) fails
// - reactor processing of a block reports failure and FSM sends back the peers of first and second blocks
func (bcR *BlockchainReactor) sendPeerError(err error, peerID p2p.ID) {
bcR.Logger.Info("sendPeerError:", "peer", peerID, "error", err)
msgData := bcFsmMessage{
Expand Down
8 changes: 6 additions & 2 deletions blockchain/v1/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ func newBlockchainReactor(

blockDB := dbm.NewMemDB()
stateDB := dbm.NewMemDB()
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
blockStore := store.NewBlockStore(blockDB)

state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
Expand All @@ -115,7 +117,9 @@ func newBlockchainReactor(
// pool.height is determined from the store.
fastSync := true
db := dbm.NewMemDB()
stateStore = sm.NewStore(db)
stateStore = sm.NewStore(db, sm.StoreOptions{
DiscardABCIResponses: false,
})
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
if err = stateStore.Save(state); err != nil {
Expand Down
12 changes: 9 additions & 3 deletions blockchain/v2/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ func newTestReactor(p testReactorParams) *BlockchainReactor {
panic(fmt.Errorf("error start app: %w", err))
}
db := dbm.NewMemDB()
stateStore := sm.NewStore(db)
stateStore := sm.NewStore(db, sm.StoreOptions{
DiscardABCIResponses: false,
})
appl = sm.NewBlockExecutor(stateStore, p.logger, proxyApp.Consensus(), mock.Mempool{}, sm.EmptyEvidencePool{})
if err = stateStore.Save(state); err != nil {
panic(err)
Expand Down Expand Up @@ -504,14 +506,18 @@ func newReactorStore(

stateDB := dbm.NewMemDB()
blockStore := store.NewBlockStore(dbm.NewMemDB())
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
state, err := stateStore.LoadFromDBOrGenesisDoc(genDoc)
if err != nil {
panic(fmt.Errorf("error constructing state from genesis file: %w", err))
}

db := dbm.NewMemDB()
stateStore = sm.NewStore(db)
stateStore = sm.NewStore(db, sm.StoreOptions{
DiscardABCIResponses: false},
)
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(),
mock.Mempool{}, sm.EmptyEvidencePool{})
if err = stateStore.Save(state); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/tendermint/commands/reindex_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ replace the backend. The default start-height is 0, meaning the tooling will sta
reindex from the base block height(inclusive); and the default end-height is 0, meaning
the tooling will reindex until the latest block height(inclusive). User can omit
either or both arguments.
Note: This operation requires ABCIResponses. Do not set DiscardABCIResponses to true if you
want to use this command.
`,
Example: `
tendermint reindex-event
Expand Down
4 changes: 3 additions & 1 deletion cmd/tendermint/commands/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func loadStateAndBlockStore(config *cfg.Config) (*store.BlockStore, state.Store,
if err != nil {
return nil, nil, err
}
stateStore := state.NewStore(stateDB)
stateStore := state.NewStore(stateDB, state.StoreOptions{
DiscardABCIResponses: config.RPC.DiscardABCIResponses,
})

return blockStore, stateStore, nil
}
18 changes: 13 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ type RPCConfig struct {

// pprof listen address (https://golang.org/pkg/net/http/pprof)
PprofListenAddress string `mapstructure:"pprof_laddr"`

// Set false to ensure ABCI responses are persisted.
// ABCI responses are required for /BlockResults RPC queries, and
// to reindex events in the command-line tool.
DiscardABCIResponses bool `mapstructure:"discard_abci_responses"`
}

// DefaultRPCConfig returns a default configuration for the RPC server
Expand All @@ -429,8 +434,9 @@ func DefaultRPCConfig() *RPCConfig {
MaxBodyBytes: int64(1000000), // 1MB
MaxHeaderBytes: 1 << 20, // same as the net/http default

TLSCertFile: "",
TLSKeyFile: "",
TLSCertFile: "",
TLSKeyFile: "",
DiscardABCIResponses: false,
}
}

Expand Down Expand Up @@ -1070,12 +1076,14 @@ func (cfg *ConsensusConfig) ValidateBasic() error {
return nil
}

//-----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// TxIndexConfig
// Remember that Event has the following structure:
// type: [
// key: value,
// ...
//
// key: value,
// ...
//
// ]
//
// CompositeKeys are constructed by `type.key`
Expand Down
8 changes: 5 additions & 3 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
for i := 0; i < nValidators; i++ {
logger := consensusLogger().With("test", "byzantine", "validator", i)
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
defer os.RemoveAll(thisConfig.RootDir)
Expand Down Expand Up @@ -446,8 +448,8 @@ func TestByzantineConflictingProposalsWithPartition(t *testing.T) {
case <-done:
case <-tick.C:
for i, reactor := range reactors {
t.Log(fmt.Sprintf("Consensus Reactor %v", i))
t.Log(fmt.Sprintf("%v", reactor))
t.Logf(fmt.Sprintf("Consensus Reactor %v", i))
t.Logf(fmt.Sprintf("%v", reactor))
}
t.Fatalf("Timed out waiting for all validators to commit first block")
}
Expand Down
12 changes: 9 additions & 3 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,9 @@ func newStateWithConfigAndBlockStore(

// Make State
stateDB := blockDB
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
if err := stateStore.Save(state); err != nil { // for save height 1's validators info
panic(err)
}
Expand Down Expand Up @@ -718,7 +720,9 @@ func randConsensusNet(nValidators int, testName string, tickerFunc func() Timeou
configRootDirs := make([]string, 0, nValidators)
for i := 0; i < nValidators; i++ {
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
configRootDirs = append(configRootDirs, thisConfig.RootDir)
Expand Down Expand Up @@ -756,7 +760,9 @@ func randConsensusNetWithPeers(
configRootDirs := make([]string, 0, nPeers)
for i := 0; i < nPeers; i++ {
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
configRootDirs = append(configRootDirs, thisConfig.RootDir)
Expand Down
4 changes: 2 additions & 2 deletions consensus/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func deliverTxsRange(cs *State, start, end int) {
func TestMempoolTxConcurrentWithCommit(t *testing.T) {
state, privVals := randGenesisState(1, false, 10)
blockDB := dbm.NewMemDB()
stateStore := sm.NewStore(blockDB)
stateStore := sm.NewStore(blockDB, sm.StoreOptions{DiscardABCIResponses: false})
cs := newStateWithConfigAndBlockStore(config, state, privVals[0], NewCounterApplication(), blockDB)
err := stateStore.Save(state)
require.NoError(t, err)
Expand All @@ -138,7 +138,7 @@ func TestMempoolRmBadTx(t *testing.T) {
state, privVals := randGenesisState(1, false, 10)
app := NewCounterApplication()
blockDB := dbm.NewMemDB()
stateStore := sm.NewStore(blockDB)
stateStore := sm.NewStore(blockDB, sm.StoreOptions{DiscardABCIResponses: false})
cs := newStateWithConfigAndBlockStore(config, state, privVals[0], app, blockDB)
err := stateStore.Save(state)
require.NoError(t, err)
Expand Down
4 changes: 3 additions & 1 deletion consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ func TestReactorWithEvidence(t *testing.T) {
logger := consensusLogger()
for i := 0; i < nValidators; i++ {
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
state, _ := stateStore.LoadFromDBOrGenesisDoc(genDoc)
thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
defer os.RemoveAll(thisConfig.RootDir)
Expand Down
2 changes: 1 addition & 1 deletion consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func (h *Handshaker) ReplayBlocks(

case appBlockHeight == storeBlockHeight:
// We ran Commit, but didn't save the state, so replayBlock with mock app.
abciResponses, err := h.stateStore.LoadABCIResponses(storeBlockHeight)
abciResponses, err := h.stateStore.LoadLastABCIResponse(storeBlockHeight)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion consensus/replay_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
if err != nil {
tmos.Exit(err.Error())
}
stateStore := sm.NewStore(stateDB)
stateStore := sm.NewStore(stateDB, sm.StoreOptions{
DiscardABCIResponses: false,
})
gdoc, err := sm.MakeGenesisDocFromFile(config.GenesisFile())
if err != nil {
tmos.Exit(err.Error())
Expand Down
Loading

0 comments on commit fbd754b

Please sign in to comment.