Skip to content

Commit

Permalink
Add occ flag check to context (#340)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
- Allows sei-chain to ask isOCCEnabled() so that it can choose to use
the OCC logic
- Sei-chain can set this to true according to desired logic

## Testing performed to validate your change
- unit test that sets flag and verifies value
  • Loading branch information
stevenlanders authored Oct 23, 2023
1 parent 096041b commit 0b9193c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Context struct {
voteInfo []abci.VoteInfo
gasMeter GasMeter
blockGasMeter GasMeter
occEnabled bool
checkTx bool
recheckTx bool // if recheckTx == true, then checkTx must also be true
minGasPrice DecCoins
Expand Down Expand Up @@ -104,6 +105,10 @@ func (c Context) IsReCheckTx() bool {
return c.recheckTx
}

func (c Context) IsOCCEnabled() bool {
return c.occEnabled
}

func (c Context) MinGasPrices() DecCoins {
return c.minGasPrice
}
Expand Down Expand Up @@ -281,6 +286,12 @@ func (c Context) WithIsCheckTx(isCheckTx bool) Context {
return c
}

// WithIsOCCEnabled enables or disables whether OCC is used as the concurrency algorithm
func (c Context) WithIsOCCEnabled(isOCCEnabled bool) Context {
c.occEnabled = isOCCEnabled
return c
}

// WithIsRecheckTx called with true will also set true on checkTx in order to
// enforce the invariant that if recheckTx = true then checkTx = true as well.
func (c Context) WithIsReCheckTx(isRecheckTx bool) Context {
Expand Down
6 changes: 5 additions & 1 deletion types/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (s *contextTestSuite) TestContextWithCustom() {
height := int64(1)
chainid := "chainid"
ischeck := true
isOCC := true
txbytes := []byte("txbytes")
logger := mocks.NewMockLogger(ctrl)
voteinfos := []abci.VoteInfo{{}}
Expand All @@ -106,10 +107,13 @@ func (s *contextTestSuite) TestContextWithCustom() {
WithGasMeter(meter).
WithMinGasPrices(minGasPrices).
WithBlockGasMeter(blockGasMeter).
WithHeaderHash(headerHash)
WithHeaderHash(headerHash).
WithIsOCCEnabled(isOCC)

s.Require().Equal(height, ctx.BlockHeight())
s.Require().Equal(chainid, ctx.ChainID())
s.Require().Equal(ischeck, ctx.IsCheckTx())
s.Require().Equal(isOCC, ctx.IsOCCEnabled())
s.Require().Equal(txbytes, ctx.TxBytes())
s.Require().Equal(logger, ctx.Logger())
s.Require().Equal(voteinfos, ctx.VoteInfos())
Expand Down

0 comments on commit 0b9193c

Please sign in to comment.