Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/celestiaorg…
Browse files Browse the repository at this point in the history
…/nmt-0.20.0
  • Loading branch information
cmwaters authored Sep 22, 2023
2 parents 96251de + 43db8d0 commit 726a8dc
Show file tree
Hide file tree
Showing 66 changed files with 1,436 additions and 1,698 deletions.
1,061 changes: 277 additions & 784 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions cmd/cometbft/commands/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,44 @@ import (
"github.com/cometbft/cometbft/store"
)

var removeBlock = false

func init() {
RollbackStateCmd.Flags().BoolVar(&removeBlock, "hard", false, "remove last block as well as state")
}

var RollbackStateCmd = &cobra.Command{
Use: "rollback",
Short: "rollback CometBFT state by one height",
Long: `
A state rollback is performed to recover from an incorrect application state transition,
when CometBFT has persisted an incorrect app hash and is thus unable to make
progress. Rollback overwrites a state at height n with the state at height n - 1.
The application should also roll back to height n - 1. No blocks are removed, so upon
restarting CometBFT the transactions in block n will be re-executed against the
application.
The application should also roll back to height n - 1. If the --hard flag is not used,
no blocks will be removed so upon restarting Tendermint the transactions in block n will be
re-executed against the application. Using --hard will also remove block n. This can
be done multiple times.
`,
RunE: func(cmd *cobra.Command, args []string) error {
height, hash, err := RollbackState(config)
height, hash, err := RollbackState(config, removeBlock)
if err != nil {
return fmt.Errorf("failed to rollback state: %w", err)
}

fmt.Printf("Rolled back state to height %d and hash %v", height, hash)
if removeBlock {
fmt.Printf("Rolled back both state and block to height %d and hash %X\n", height, hash)
} else {
fmt.Printf("Rolled back state to height %d and hash %X\n", height, hash)
}

return nil
},
}

// RollbackState takes the state at the current height n and overwrites it with the state
// at height n - 1. Note state here refers to CometBFT state not application state.
// Returns the latest state height and app hash alongside an error if there was one.
func RollbackState(config *cfg.Config) (int64, []byte, error) {
func RollbackState(config *cfg.Config, removeBlock bool) (int64, []byte, error) {
// use the parsed config to load the block and state store
blockStore, stateStore, err := loadStateAndBlockStore(config)
if err != nil {
Expand All @@ -51,7 +63,7 @@ func RollbackState(config *cfg.Config) (int64, []byte, error) {
}()

// rollback the last state
return state.Rollback(blockStore, stateStore)
return state.Rollback(blockStore, stateStore, removeBlock)
}

func loadStateAndBlockStore(config *cfg.Config) (*store.BlockStore, state.Store, error) {
Expand Down
8 changes: 4 additions & 4 deletions consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ func (h *Handshaker) ReplayBlocks(
}
validatorSet := types.NewValidatorSet(validators)
nextVals := types.TM2PB.ValidatorUpdates(validatorSet)
csParams := types.TM2PB.ConsensusParams(h.genDoc.ConsensusParams)
pbparams := h.genDoc.ConsensusParams.ToProto()
req := abci.RequestInitChain{
Time: h.genDoc.GenesisTime,
ChainId: h.genDoc.ChainID,
InitialHeight: h.genDoc.InitialHeight,
ConsensusParams: csParams,
ConsensusParams: &pbparams,
Validators: nextVals,
AppStateBytes: h.genDoc.AppState,
}
Expand Down Expand Up @@ -344,8 +344,8 @@ func (h *Handshaker) ReplayBlocks(
}

if res.ConsensusParams != nil {
state.ConsensusParams = types.UpdateConsensusParams(state.ConsensusParams, res.ConsensusParams)
state.Version.Consensus.App = state.ConsensusParams.Version.AppVersion
state.ConsensusParams = state.ConsensusParams.Update(res.ConsensusParams)
state.Version.Consensus.App = state.ConsensusParams.Version.App
}
// We update the last results hash with the empty hash, to conform with RFC-6962.
state.LastResultsHash = merkle.HashFromByteSlices(nil)
Expand Down
6 changes: 4 additions & 2 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,14 +1191,14 @@ func stateAndStore(

type mockBlockStore struct {
config *cfg.Config
params cmtproto.ConsensusParams
params types.ConsensusParams
chain []*types.Block
commits []*types.Commit
base int64
}

// TODO: NewBlockStore(db.NewMemDB) ...
func newMockBlockStore(config *cfg.Config, params cmtproto.ConsensusParams) *mockBlockStore {
func newMockBlockStore(config *cfg.Config, params types.ConsensusParams) *mockBlockStore {
return &mockBlockStore{config, params, nil, nil, 0}
}

Expand Down Expand Up @@ -1241,6 +1241,8 @@ func (bs *mockBlockStore) PruneBlocks(height int64) (uint64, error) {
return pruned, nil
}

func (bs *mockBlockStore) DeleteLatestBlock() error { return nil }

//---------------------------------------
// Test handshake/init chain

Expand Down
5 changes: 3 additions & 2 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2250,9 +2250,10 @@ func (cs *State) signVote(
func (cs *State) voteTime() time.Time {
now := cmttime.Now()
minVoteTime := now
// Minimum time increment between blocks
const timeIota = time.Millisecond
// TODO: We should remove next line in case we don't vote for v in case cs.ProposalBlock == nil,
// even if cs.LockedBlock != nil. See https://github.com/cometbft/cometbft/tree/v0.34.x/spec/.
timeIota := time.Duration(cs.state.ConsensusParams.Block.TimeIotaMs) * time.Millisecond
// even if cs.LockedBlock != nil. See https://docs.tendermint.com/master/spec/.
if cs.LockedBlock != nil {
// See the BFT time spec
// https://github.com/cometbft/cometbft/blob/v0.34.x/spec/consensus/bft-time.md
Expand Down
2 changes: 1 addition & 1 deletion evidence/mocks/block_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions evidence/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/cometbft/cometbft/evidence"
"github.com/cometbft/cometbft/evidence/mocks"
"github.com/cometbft/cometbft/libs/log"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtversion "github.com/cometbft/cometbft/proto/tendermint/version"
sm "github.com/cometbft/cometbft/state"
smmocks "github.com/cometbft/cometbft/state/mocks"
Expand Down Expand Up @@ -326,12 +325,12 @@ func TestRecoverPendingEvidence(t *testing.T) {
newStateStore.On("Load").Return(sm.State{
LastBlockTime: defaultEvidenceTime.Add(25 * time.Minute),
LastBlockHeight: height + 15,
ConsensusParams: cmtproto.ConsensusParams{
Block: cmtproto.BlockParams{
ConsensusParams: types.ConsensusParams{
Block: types.BlockParams{
MaxBytes: 22020096,
MaxGas: -1,
},
Evidence: cmtproto.EvidenceParams{
Evidence: types.EvidenceParams{
MaxAgeNumBlocks: 20,
MaxAgeDuration: 20 * time.Minute,
MaxBytes: defaultEvidenceMaxBytes,
Expand Down Expand Up @@ -361,12 +360,12 @@ func initializeStateFromValidatorSet(valSet *types.ValidatorSet, height int64) s
NextValidators: valSet.CopyIncrementProposerPriority(1),
LastValidators: valSet,
LastHeightValidatorsChanged: 1,
ConsensusParams: cmtproto.ConsensusParams{
Block: cmtproto.BlockParams{
ConsensusParams: types.ConsensusParams{
Block: types.BlockParams{
MaxBytes: 22020096,
MaxGas: -1,
},
Evidence: cmtproto.EvidenceParams{
Evidence: types.EvidenceParams{
MaxAgeNumBlocks: 20,
MaxAgeDuration: 20 * time.Minute,
MaxBytes: 1000,
Expand Down
4 changes: 2 additions & 2 deletions light/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (c *Client) ConsensusParams(ctx context.Context, height *int64) (*ctypes.Re
}

// Validate res.
if err := types.ValidateConsensusParams(res.ConsensusParams); err != nil {
if err := res.ConsensusParams.ValidateBasic(); err != nil {
return nil, err
}
if res.BlockHeight <= 0 {
Expand All @@ -248,7 +248,7 @@ func (c *Client) ConsensusParams(ctx context.Context, height *int64) (*ctypes.Re
}

// Verify hash.
if cH, tH := types.HashConsensusParams(res.ConsensusParams), l.ConsensusHash; !bytes.Equal(cH, tH) {
if cH, tH := res.ConsensusParams.Hash(), l.ConsensusHash; !bytes.Equal(cH, tH) {
return nil, fmt.Errorf("params hash %X does not match trusted hash %X",
cH, tH)
}
Expand Down
4 changes: 4 additions & 0 deletions mempool/v1/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ func (memR *Reactor) broadcastTxRoutine(peer p2p.Peer) {
if !success {
time.Sleep(mempool.PeerCatchupSleepIntervalMS * time.Millisecond)
continue
} else {
// record that we have sent the peer the transaction
// to avoid doing it a second time
memTx.SetPeer(peerID)
}
}

Expand Down
40 changes: 12 additions & 28 deletions proto/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ message RequestInfo {
string version = 1;
uint64 block_version = 2;
uint64 p2p_version = 3;
string abci_version = 4;
}

message RequestInitChain {
google.protobuf.Timestamp time = 1
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
string chain_id = 2;
ConsensusParams consensus_params = 3;
repeated ValidatorUpdate validators = 4 [(gogoproto.nullable) = false];
bytes app_state_bytes = 5;
int64 initial_height = 6;
string chain_id = 2;
tendermint.types.ConsensusParams consensus_params = 3;
repeated ValidatorUpdate validators = 4 [(gogoproto.nullable) = false];
bytes app_state_bytes = 5;
int64 initial_height = 6;
}

message RequestQuery {
Expand Down Expand Up @@ -196,9 +197,9 @@ message ResponseInfo {
}

message ResponseInitChain {
ConsensusParams consensus_params = 1;
repeated ValidatorUpdate validators = 2 [(gogoproto.nullable) = false];
bytes app_hash = 3;
tendermint.types.ConsensusParams consensus_params = 1;
repeated ValidatorUpdate validators = 2 [(gogoproto.nullable) = false];
bytes app_hash = 3;
}

message ResponseQuery {
Expand Down Expand Up @@ -252,9 +253,9 @@ message ResponseDeliverTx {
}

message ResponseEndBlock {
repeated ValidatorUpdate validator_updates = 1 [(gogoproto.nullable) = false];
ConsensusParams consensus_param_updates = 2;
repeated Event events = 3
repeated ValidatorUpdate validator_updates = 1 [(gogoproto.nullable) = false];
tendermint.types.ConsensusParams consensus_param_updates = 2;
repeated Event events = 3
[(gogoproto.nullable) = false, (gogoproto.jsontag) = "events,omitempty"];
}

Expand Down Expand Up @@ -320,23 +321,6 @@ message ResponseProcessProposal {
//----------------------------------------
// Misc.

// ConsensusParams contains all consensus-relevant parameters
// that can be adjusted by the abci app
message ConsensusParams {
BlockParams block = 1;
tendermint.types.EvidenceParams evidence = 2;
tendermint.types.ValidatorParams validator = 3;
tendermint.types.VersionParams version = 4;
}

// BlockParams contains limits on the block size.
message BlockParams {
// Note: must be greater than 0
int64 max_bytes = 1;
// Note: must be greater or equal to -1
int64 max_gas = 2;
}

message CommitInfo {
int32 round = 1;
repeated VoteInfo votes = 2 [(gogoproto.nullable) = false];
Expand Down
52 changes: 26 additions & 26 deletions proto/tendermint/blockchain/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 726a8dc

Please sign in to comment.