Skip to content

Commit

Permalink
first pass at changes allowing nodes to call PrepareProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
MaghnusM committed Sep 11, 2023
1 parent 65f7a2f commit b7f8312
Show file tree
Hide file tree
Showing 39 changed files with 403 additions and 321 deletions.
460 changes: 251 additions & 209 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
// proposed will have a valid timestamp
lazyProposer := css[1]

lazyProposer.decideProposal = func(height int64, round int32) {
lazyProposer.decideProposal = func(height int64, round int32, isNonProposingNode bool) {
lazyProposer.Logger.Info("Lazy Proposer proposing condensed commit")
if lazyProposer.privValidator == nil {
panic("entered createProposalBlock with privValidator being nil")
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
proposerAddr := lazyProposer.privValidatorPubKey.Address()

block, err := lazyProposer.blockExec.CreateProposalBlock(
lazyProposer.Height, lazyProposer.state, commit, proposerAddr)
lazyProposer.Height, lazyProposer.state, commit, proposerAddr, false)
require.NoError(t, err)
blockParts, err := block.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
Expand Down Expand Up @@ -346,8 +346,8 @@ func TestByzantineConflictingProposalsWithPartition(t *testing.T) {
// NOTE: Now, test validators are MockPV, which by default doesn't
// do any safety checks.
css[i].privValidator.(types.MockPV).DisableChecks()
css[i].decideProposal = func(j int32) func(int64, int32) {
return func(height int64, round int32) {
css[i].decideProposal = func(j int32) func(int64, int32, bool) {
return func(height int64, round int32, isNonProposingNode bool) {
byzantineDecideProposalFunc(t, height, round, css[j], switches[j])
}
}(int32(i))
Expand Down Expand Up @@ -472,7 +472,7 @@ func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *St
// Avoid sending on internalMsgQueue and running consensus state.

// Create a new proposal block from state/txs from the mempool.
block1, err := cs.createProposalBlock()
block1, err := cs.createProposalBlock(false)
require.NoError(t, err)
blockParts1, err := block1.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
Expand All @@ -489,7 +489,7 @@ func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *St
deliverTxsRange(cs, 0, 1)

// Create a new proposal block from state/txs from the mempool.
block2, err := cs.createProposalBlock()
block2, err := cs.createProposalBlock(false)
require.NoError(t, err)
blockParts2, err := block2.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func decideProposal(
round int32,
) (proposal *types.Proposal, block *types.Block) {
cs1.mtx.Lock()
block, err := cs1.createProposalBlock()
block, err := cs1.createProposalBlock(false)
require.NoError(t, err)
blockParts, err := block.MakePartSet(types.BlockPartSizeBytes)
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
err = assertMempool(css[0].txNotifier).CheckTx(newValidatorTx1, nil, mempl.TxInfo{})
assert.NoError(t, err)
propBlock, err := css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, err := css[0].createProposalBlock(false) // changeProposer(t, cs1, vs2)
require.NoError(t, err)
propBlockParts, err := propBlock.MakePartSet(partSize)
require.NoError(t, err)
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
err = assertMempool(css[0].txNotifier).CheckTx(updateValidatorTx1, nil, mempl.TxInfo{})
assert.NoError(t, err)
propBlock, err = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, err = css[0].createProposalBlock(false) // changeProposer(t, cs1, vs2)
require.NoError(t, err)
propBlockParts, err = propBlock.MakePartSet(partSize)
require.NoError(t, err)
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
err = assertMempool(css[0].txNotifier).CheckTx(newValidatorTx3, nil, mempl.TxInfo{})
assert.NoError(t, err)
propBlock, err = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, err = css[0].createProposalBlock(false) // changeProposer(t, cs1, vs2)
require.NoError(t, err)
propBlockParts, err = propBlock.MakePartSet(partSize)
require.NoError(t, err)
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
err = assertMempool(css[0].txNotifier).CheckTx(removeValidatorTx3, nil, mempl.TxInfo{})
assert.NoError(t, err)
propBlock, err = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, err = css[0].createProposalBlock(false) // changeProposer(t, cs1, vs2)
require.NoError(t, err)
propBlockParts, err = propBlock.MakePartSet(partSize)
require.NoError(t, err)
Expand Down
35 changes: 29 additions & 6 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type State struct {
nSteps int

// some functions can be overwritten for testing
decideProposal func(height int64, round int32)
decideProposal func(height int64, round int32, isNonProposingNode bool)
doPrevote func(height int64, round int32)
setProposal func(proposal *types.Proposal) error

Expand Down Expand Up @@ -1117,12 +1117,13 @@ func (cs *State) enterPropose(height int64, round int32) {
// if not a validator, we're done
if !cs.Validators.HasAddress(address) {
logger.Debug("node is not a validator", "addr", address, "vals", cs.Validators)
cs.decideProposal(height, round, true)
return
}

if cs.isProposer(address) {
logger.Debug("propose step; our turn to propose", "proposer", address)
cs.decideProposal(height, round)
cs.decideProposal(height, round, false)
} else {
logger.Debug("propose step; not our turn to propose", "proposer", cs.Validators.GetProposer().Address)
}
Expand All @@ -1132,18 +1133,31 @@ func (cs *State) isProposer(address []byte) bool {
return bytes.Equal(cs.Validators.GetProposer().Address, address)
}

func (cs *State) defaultDecideProposal(height int64, round int32) {
func (cs *State) defaultDecideProposal(height int64, round int32, isNonProposingNode bool) {
var block *types.Block
var blockParts *types.PartSet

if isNonProposingNode {
// Create a new proposal block from state/txs from the mempool.
var err error
block, err = cs.createProposalBlock(isNonProposingNode)
if err != nil {
cs.Logger.Error("unable to create proposal block as a non-proposing node", "error", err)
return
} else if block == nil {
cs.Logger.Error("error", "error", "Method createProposalBlock should not provide a nil block without errors")
}
return
}

// Decide on block
if cs.ValidBlock != nil {
// If there is valid block, choose that.
block, blockParts = cs.ValidBlock, cs.ValidBlockParts
} else {
// Create a new proposal block from state/txs from the mempool.
var err error
block, err = cs.createProposalBlock()
block, err = cs.createProposalBlock(isNonProposingNode)
if err != nil {
cs.Logger.Error("unable to create proposal block", "error", err)
return
Expand Down Expand Up @@ -1207,7 +1221,16 @@ func (cs *State) isProposalComplete() bool {
//
// NOTE: keep it side-effect free for clarity.
// CONTRACT: cs.privValidator is not nil.
func (cs *State) createProposalBlock() (*types.Block, error) {
func (cs *State) createProposalBlock(isNonProposingNode bool) (*types.Block, error) {

if isNonProposingNode {
ret, err := cs.blockExec.CreateProposalBlock(0, cs.state, nil, nil, isNonProposingNode)
if err != nil {
return ret, err
}
return ret, nil
}

if cs.privValidator == nil {
return nil, errors.New("entered createProposalBlock with privValidator being nil")
}
Expand Down Expand Up @@ -1235,7 +1258,7 @@ func (cs *State) createProposalBlock() (*types.Block, error) {

proposerAddr := cs.privValidatorPubKey.Address()

ret, err := cs.blockExec.CreateProposalBlock(cs.Height, cs.state, commit, proposerAddr)
ret, err := cs.blockExec.CreateProposalBlock(cs.Height, cs.state, commit, proposerAddr, isNonProposingNode)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestStateBadProposal(t *testing.T) {
proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
voteCh := subscribe(cs1.eventBus, types.EventQueryVote)

propBlock, err := cs1.createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, err := cs1.createProposalBlock(false) // changeProposer(t, cs1, vs2)
require.NoError(t, err)

// make the second validator the proposer by incrementing round
Expand Down
2 changes: 1 addition & 1 deletion proto/dydxcometbft/clob/matches.pb.go

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

3 changes: 1 addition & 2 deletions proto/dydxcometbft/clob/order.pb.go

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

9 changes: 4 additions & 5 deletions proto/dydxcometbft/clob/tx.pb.go

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

2 changes: 1 addition & 1 deletion proto/dydxcometbft/subaccounts/asset_position.pb.go

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

2 changes: 1 addition & 1 deletion proto/dydxcometbft/subaccounts/perpetual_position.pb.go

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

2 changes: 1 addition & 1 deletion proto/dydxcometbft/subaccounts/subaccount.pb.go

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

2 changes: 2 additions & 0 deletions proto/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ message RequestPrepareProposal {
bytes next_validators_hash = 7;
// address of the public key of the validator proposing the block.
bytes proposer_address = 8;
// true/false value if calling PrepareProposal as a non-proposing-node
bool is_non_proposing_node = 9;
}

message RequestProcessProposal {
Expand Down
2 changes: 1 addition & 1 deletion proto/tendermint/blocksync/types.pb.go

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

2 changes: 1 addition & 1 deletion proto/tendermint/consensus/types.pb.go

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

16 changes: 8 additions & 8 deletions proto/tendermint/consensus/wal.pb.go

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

3 changes: 1 addition & 2 deletions proto/tendermint/crypto/keys.pb.go

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

2 changes: 1 addition & 1 deletion proto/tendermint/crypto/proof.pb.go

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

2 changes: 1 addition & 1 deletion proto/tendermint/libs/bits/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 b7f8312

Please sign in to comment.