Skip to content

Commit

Permalink
go/beacon: Only allow a single beacon transaction per block
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Feb 3, 2021
1 parent 02d20b3 commit 4d27e86
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions go/consensus/tendermint/apps/beacon/backend_pvss.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ var (
validatorEntropyCtx = []byte("EkB-validator")
)

// beaconTransactionIncludedKey is the block context key for storing the beacon transaction
// inclusion flag to make sure that only a single beacon transaction is included.
type beaconTransactionIncludedKey struct{}

func (bti beaconTransactionIncludedKey) NewDefault() interface{} {
return false
}

type backendPVSS struct {
app *beaconApplication
}
Expand Down Expand Up @@ -550,8 +558,7 @@ func (impl *backendPVSS) ExecuteTx(
// time out due to the processing overhead.
//
// In an ideal world, beacon tx-es shouldn't be gossiped to begin
// with (and be rejected if received), and each block should be
// limited to one beacon tx.
// with.
switch {
case ctx.IsCheckOnly():
// During CheckTx do the quick check and only accept own transactions.
Expand All @@ -571,6 +578,12 @@ func (impl *backendPVSS) ExecuteTx(
if !ctx.TxSigner().Equal(proposerNodeID) {
return fmt.Errorf("beacon: rejecting beacon tx not from proposer (proposer: %s signer: %s)", proposerNodeID, ctx.TxSigner())
}

// Also make sure that there is only a single beacon transaction in a block.
if ctx.BlockContext().Get(beaconTransactionIncludedKey{}).(bool) {
return fmt.Errorf("beacon: rejecting multiple beacon txes per block")
}
ctx.BlockContext().Set(beaconTransactionIncludedKey{}, true)
}
return impl.doPVSSTx(ctx, state, params, tx)
case MethodSetEpoch:
Expand Down

0 comments on commit 4d27e86

Please sign in to comment.