@@ -2,7 +2,6 @@ package staker
22
33import (
44 "context"
5- "fmt"
65
76 "github.com/ethereum/go-ethereum/common"
87 "github.com/ethereum/go-ethereum/log"
@@ -18,19 +17,16 @@ import (
1817type MELEnabledValidationEntryCreator struct {
1918 melValidator MELValidatorInterface
2019 txStreamer TransactionStreamerInterface
21- melRunner MELRunnerInterface
2220}
2321
2422// NewMELEnabledValidationEntryCreator creates a new instance of MELEnabledValidationEntryCreator.
2523func NewMELEnabledValidationEntryCreator (
2624 melValidator MELValidatorInterface ,
2725 txStreamer TransactionStreamerInterface ,
28- melRunner MELRunnerInterface ,
2926) * MELEnabledValidationEntryCreator {
3027 return & MELEnabledValidationEntryCreator {
3128 melValidator : melValidator ,
3229 txStreamer : txStreamer ,
33- melRunner : melRunner ,
3430 }
3531}
3632
@@ -61,13 +57,6 @@ func (m *MELEnabledValidationEntryCreator) CreateBlockValidationEntry(
6157 if err != nil {
6258 return nil , created , err
6359 }
64- melStateForMsg , err := m .melRunner .GetState (ctx , msg .Message .Header .BlockNumber )
65- if err != nil {
66- return nil , created , err
67- }
68- if melStateForMsg .MsgCount == 0 {
69- return nil , created , fmt .Errorf ("MEL state for msg at position %d has 0 msg count" , position )
70- }
7160 prevResult , err := m .txStreamer .ResultAtMessageIndex (arbutil .MessageIndex (position ) - 1 )
7261 if err != nil {
7362 return nil , created , err
@@ -80,38 +69,48 @@ func (m *MELEnabledValidationEntryCreator) CreateBlockValidationEntry(
8069 preimages := make (daprovider.PreimagesMap )
8170 preimages [arbutil .Keccak256PreimageType ] = make (map [common.Hash ][]byte )
8271
83- // Add MEL state to the preimages map .
84- encodedInitialState , err := rlp . EncodeToBytes ( latestValidatedMELState )
72+ // Fetch and add the msg releated preimages .
73+ msgPreimagesAndRelevantState , err := m . melValidator . FetchMsgPreimagesAndRelevantState ( ctx , position )
8574 if err != nil {
8675 return nil , created , err
8776 }
88- preimages [ arbutil . Keccak256PreimageType ][ latestValidatedMELState . Hash ()] = encodedInitialState
77+ validator . CopyPreimagesInto ( preimages , msgPreimagesAndRelevantState . msgPreimages )
8978
90- // Fetch and add the msg releated preimages.
91- msgPreimages , err := m .melValidator .FetchMsgPreimages (ctx , uint64 (position ), melStateForMsg .ParentChainBlockNumber )
79+ // Add relevant MEL state to the preimages map.
80+ relevantMELState := msgPreimagesAndRelevantState .relevantState
81+ encodedInitialState , err := rlp .EncodeToBytes (relevantMELState )
9282 if err != nil {
9383 return nil , created , err
9484 }
95- validator .CopyPreimagesInto (preimages , msgPreimages )
85+ preimages [arbutil .Keccak256PreimageType ][relevantMELState .Hash ()] = encodedInitialState
86+
9687 startGs := validator.GoGlobalState {
9788 BlockHash : prevResult .BlockHash ,
9889 SendRoot : prevResult .SendRoot ,
99- MELStateHash : latestValidatedMELState .Hash (),
90+ MELStateHash : relevantMELState .Hash (),
10091 MELMsgHash : msg .Hash (),
10192 PosInBatch : uint64 (position ),
10293 }
94+ endGsMELMsgHash := common.Hash {}
95+ if relevantMELState .MsgCount > uint64 (position )+ 1 {
96+ nextMsg , err := m .txStreamer .GetMessage (position + 1 )
97+ if err != nil {
98+ return nil , created , err
99+ }
100+ endGsMELMsgHash = nextMsg .Hash ()
101+ }
103102 endGlobalState := validator.GoGlobalState {
104103 BlockHash : executionResult .BlockHash ,
105104 SendRoot : executionResult .SendRoot ,
106- MELStateHash : latestValidatedMELState .Hash (),
107- MELMsgHash : msg . Hash () ,
105+ MELStateHash : relevantMELState .Hash (),
106+ MELMsgHash : endGsMELMsgHash ,
108107 PosInBatch : uint64 (position ) + 1 ,
109108 }
110109 chainConfig := m .txStreamer .ChainConfig ()
111110 created = true
112111 return & validationEntry {
113112 Stage : ReadyForRecord ,
114- Pos : arbutil . MessageIndex ( position ) ,
113+ Pos : position ,
115114 Start : startGs ,
116115 End : endGlobalState ,
117116 msg : msg ,
0 commit comments