Skip to content

Commit

Permalink
refactor MessageRunContext methods
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Nov 14, 2024
1 parent fd4538a commit 956e649
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,32 +162,34 @@ type Message struct {
SkipL1Charging bool
}

type messageRunMode uint8

const (
messageCommitMode messageRunMode = iota
messageGasEstimationMode
messageEthcallMode
messageReplayMode
)

type MessageRunContext struct {
chainTip bool
call bool // TODO: rename or refactor the bool flags
mutating bool
executedOnChain bool
gasEstimation bool // TODO: rename
runMode messageRunMode

wasmCacheTag uint32
wasmTargets []ethdb.WasmTarget
}

func NewMessageCommitContext(wasmTargets []ethdb.WasmTarget) *MessageRunContext {
return &MessageRunContext{
chainTip: true,
mutating: true,
executedOnChain: true,
wasmCacheTag: 1,
wasmTargets: wasmTargets,
runMode: messageCommitMode,
wasmCacheTag: 1,
wasmTargets: wasmTargets,
}
}

func NewMessageReplayContext(wasmTargets []ethdb.WasmTarget) *MessageRunContext {
return &MessageRunContext{
mutating: true,
executedOnChain: true,
wasmTargets: wasmTargets,
runMode: messageReplayMode,
wasmTargets: wasmTargets,
}
}

Expand All @@ -197,45 +199,45 @@ func NewMessagePrefetchContext(wasmTargets []ethdb.WasmTarget) *MessageRunContex

func NewMessageEthcallContext() *MessageRunContext {
return &MessageRunContext{
call: true,
runMode: messageEthcallMode,
wasmTargets: []ethdb.WasmTarget{rawdb.LocalTarget()},
}
}

func NewMessageGasEstimationContext() *MessageRunContext {
return &MessageRunContext{
gasEstimation: true,
wasmTargets: []ethdb.WasmTarget{rawdb.LocalTarget()},
runMode: messageGasEstimationMode,
wasmTargets: []ethdb.WasmTarget{rawdb.LocalTarget()},
}
}

func (m *MessageRunContext) IsChainTip() bool {
return m.chainTip
func (c *MessageRunContext) IsCommitMode() bool {
return c.runMode == messageCommitMode
}

// these message modes are executed onchain so cannot make any gas shortcuts
func (m *MessageRunContext) ExecutedOnChain() bool {
return m.executedOnChain
func (c *MessageRunContext) IsExecutedOnChain() bool {
return c.runMode == messageCommitMode || c.runMode == messageReplayMode
}

func (m *MessageRunContext) IsGasEstimation() bool {
return m.gasEstimation
func (c *MessageRunContext) IsGasEstimation() bool {
return c.runMode == messageGasEstimationMode
}

func (m *MessageRunContext) IsMutating() bool {
return m.mutating
func (c *MessageRunContext) IsNonMutating() bool {
return c.runMode == messageGasEstimationMode || c.runMode == messageEthcallMode
}

func (m *MessageRunContext) IsCall() bool {
return m.call
func (c *MessageRunContext) IsEthcall() bool {
return c.runMode == messageEthcallMode
}

func (m *MessageRunContext) WasmCacheTag() uint32 {
return m.wasmCacheTag
func (c *MessageRunContext) WasmCacheTag() uint32 {
return c.wasmCacheTag
}

func (m *MessageRunContext) WasmTargets() []ethdb.WasmTarget {
return m.wasmTargets
func (c *MessageRunContext) WasmTargets() []ethdb.WasmTarget {
return c.wasmTargets
}

// TransactionToMessage converts a transaction into a Message.
Expand Down

0 comments on commit 956e649

Please sign in to comment.