Skip to content

Commit

Permalink
Merge pull request #141 from zacshowa/update-validator
Browse files Browse the repository at this point in the history
Refactor and expand validator preconditions to espresso STF logic
  • Loading branch information
zacshowa authored Jul 10, 2024
2 parents e34c95d + 966f22c commit 1b57f6a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
46 changes: 46 additions & 0 deletions cmd/replay/espresso_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"fmt"
"github.com/offchainlabs/nitro/arbos"
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/wavmio"
)

// / Handle Espresso Pre Conditions
// /
// / Description: This function takes in the most recently received message (of type arbostypes.MessageWithMetadata),
// / and a boolean from the ChainConfig
// / and uses the parameters to perform all checks gating the modified STF logic in the arbitrum validator.
// /
// / Return: A boolean representing the result of a logical and of all checks (that don't result in panics) gating espressos STF logic.
// /
// / Panics: This function will panic if the message type is not an espresso message, but the HotShot height is non-zero
// / as this is an invalid state for the STF to reside in.
// /
func handleEspressoPreConditions(message *arbostypes.MessageWithMetadata, isEnabled bool) (bool, func()) {
// calculate and cache all values needed to determine if the preconditions are met to enter the Espresso STF logic
isNonEspressoMessage := arbos.IsL2NonEspressoMsg(message.Message)
hotshotHeight := wavmio.GetEspressoHeight()

validatingEspressoLivenessFailure := isNonEspressoMessage && isEnabled
validatingEspressoHeightFailure := isNonEspressoMessage && hotshotHeight != 0
validatingAgainstEspresso := arbos.IsEspressoMsg(message.Message) && isEnabled

if validatingEspressoLivenessFailure {
// previously this was the only other branch that was checked when `validatingAgainstEspresso`
return validatingAgainstEspresso, func() {
l1Block := message.Message.Header.BlockNumber
if wavmio.IsHotShotLive(l1Block) {
panic(fmt.Sprintf("getting the centralized message while hotshot is good, l1Height: %v", l1Block))
}
}
} else if validatingEspressoHeightFailure {
// If conditions are such that we have been working in espresso mode, but we are suddenly receiving non espresso messages,
// something incorrect has occurred and we must panic
return validatingAgainstEspresso, func() {
panic("The messaged received by the STF is not an Espresso message, but the validator is running in Espresso mode")
}
}
return validatingAgainstEspresso, nil // return nil for the panic handler such that it is a no-op in the caller if no errors need occur.
}
12 changes: 5 additions & 7 deletions cmd/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ func main() {
return wavmio.ReadInboxMessage(batchNum), nil
}

validatingAgainstEspresso := arbos.IsEspressoMsg(message.Message) && chainConfig.ArbitrumChainParams.EnableEspresso
validatingEspressoLivenessFailure := arbos.IsL2NonEspressoMsg(message.Message) && chainConfig.ArbitrumChainParams.EnableEspresso
// Handle the various pre-conditions and panics that can happen before we should enter the espresso logic in the validators STF
validatingAgainstEspresso, panicHandler := handleEspressoPreConditions(message, chainConfig.ArbitrumChainParams.EnableEspresso)
if validatingAgainstEspresso {
txs, jst, err := arbos.ParseEspressoMsg(message.Message)
if err != nil {
Expand Down Expand Up @@ -325,11 +325,9 @@ func main() {
espressocrypto.VerifyNamespace(chainConfig.ChainID.Uint64(), *jst.Proof, *jst.Header.PayloadCommitment, *jst.Header.NsTable, txs, *jst.VidCommon)
}

} else if validatingEspressoLivenessFailure {
l1Block := message.Message.Header.BlockNumber
if wavmio.IsHotShotLive(l1Block) {
panic(fmt.Sprintf("getting the centralized message while hotshot is good, l1Height: %v", l1Block))
}
} else if panicHandler != nil {
// Call the error case closure returned by handleEspressoPreconditions() if it isn't nil
panicHandler()
}

newBlock, _, err = arbos.ProduceBlock(message.Message, message.DelayedMessagesRead, lastBlockHeader, statedb, chainContext, chainConfig, batchFetcher, false)
Expand Down

0 comments on commit 1b57f6a

Please sign in to comment.