From 0b9193ce54393443d11e64044c3c9abe6c13f282 Mon Sep 17 00:00:00 2001 From: Steven Landers Date: Mon, 23 Oct 2023 11:40:06 -0400 Subject: [PATCH] Add occ flag check to context (#340) ## 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 --- types/context.go | 11 +++++++++++ types/context_test.go | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/types/context.go b/types/context.go index ef847d3a3..e36e88dc8 100644 --- a/types/context.go +++ b/types/context.go @@ -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 @@ -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 } @@ -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 { diff --git a/types/context_test.go b/types/context_test.go index 92f5dccaf..e49a82903 100644 --- a/types/context_test.go +++ b/types/context_test.go @@ -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{{}} @@ -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())