forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from zacshowa/update-validator
Refactor and expand validator preconditions to espresso STF logic
- Loading branch information
Showing
2 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters