Skip to content

Commit

Permalink
Merge branch 'master' into store_last_pruned_message
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi authored Jan 6, 2025
2 parents 0ec22b1 + 41ad6fa commit b818574
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 68 deletions.
2 changes: 2 additions & 0 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func ConfigDefaultL1NonSequencerTest() *Config {
config.Staker = legacystaker.TestL1ValidatorConfig
config.Staker.Enable = false
config.BlockValidator.ValidationServerConfigs = []rpcclient.ClientConfig{{URL: ""}}
config.Bold.MinimumGapToParentAssertion = 0

return &config
}
Expand All @@ -230,6 +231,7 @@ func ConfigDefaultL2Test() *Config {
config.Staker.Enable = false
config.BlockValidator.ValidationServerConfigs = []rpcclient.ClientConfig{{URL: ""}}
config.TransactionStreamer = DefaultTransactionStreamerConfig
config.Bold.MinimumGapToParentAssertion = 0

return &config
}
Expand Down
7 changes: 3 additions & 4 deletions arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
Expand Down Expand Up @@ -123,13 +122,13 @@ func NewArbosMemoryBackedArbOSState() (*ArbosState, *state.StateDB) {
db := state.NewDatabaseWithConfig(raw, trieConfig)
statedb, err := state.New(common.Hash{}, db, nil)
if err != nil {
log.Crit("failed to init empty statedb", "error", err)
panic("failed to init empty statedb: " + err.Error())
}
burner := burn.NewSystemBurner(nil, false)
chainConfig := chaininfo.ArbitrumDevTestChainConfig()
newState, err := InitializeArbosState(statedb, burner, chainConfig, arbostypes.TestInitMessage)
if err != nil {
log.Crit("failed to open the ArbOS state", "error", err)
panic("failed to open the ArbOS state: " + err.Error())
}
return newState, statedb
}
Expand All @@ -139,7 +138,7 @@ func ArbOSVersion(stateDB vm.StateDB) uint64 {
backingStorage := storage.NewGeth(stateDB, burn.NewSystemBurner(nil, false))
arbosVersion, err := backingStorage.GetUint64ByUint64(uint64(versionOffset))
if err != nil {
log.Crit("failed to get the ArbOS version", "error", err)
panic("failed to get the ArbOS version: " + err.Error())
}
return arbosVersion
}
Expand Down
4 changes: 2 additions & 2 deletions arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
}()
statedb, err := state.New(common.Hash{}, stateDatabase, nil)
if err != nil {
log.Crit("failed to init empty statedb", "error", err)
panic("failed to init empty statedb :" + err.Error())
}

noStateTrieChangesToCommitError := regexp.MustCompile("^triedb layer .+ is disk layer$")
Expand Down Expand Up @@ -96,7 +96,7 @@ func InitializeArbosInDatabase(db ethdb.Database, cacheConfig *core.CacheConfig,
burner := burn.NewSystemBurner(nil, false)
arbosState, err := InitializeArbosState(statedb, burner, chainConfig, initMessage)
if err != nil {
log.Crit("failed to open the ArbOS state", "error", err)
panic("failed to open the ArbOS state :" + err.Error())
}

chainOwner, err := initData.GetChainOwner()
Expand Down
12 changes: 6 additions & 6 deletions arbos/programs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
package programs

import (
"strconv"

"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/arbos/util"
Expand Down Expand Up @@ -151,7 +152,7 @@ func newApiClosures(
case vm.STATICCALL:
ret, returnGas, err = evm.StaticCall(scope.Contract, contract, input, gas)
default:
log.Crit("unsupported call type", "opcode", opcode)
panic("unsupported call type: " + opcode.String())
}

interpreter.SetReturnData(ret)
Expand Down Expand Up @@ -266,7 +267,7 @@ func newApiClosures(
original := input

crash := func(reason string) {
log.Crit("bad API call", "reason", reason, "request", req, "len", len(original), "remaining", len(input))
panic("bad API call reason: " + reason + " request: " + strconv.Itoa(int(req)) + " len: " + strconv.Itoa(len(original)) + " remaining: " + strconv.Itoa(len(input)))
}
takeInput := func(needed int, reason string) []byte {
if len(input) < needed {
Expand Down Expand Up @@ -338,7 +339,7 @@ func newApiClosures(
case StaticCall:
opcode = vm.STATICCALL
default:
log.Crit("unsupported call type", "opcode", opcode)
panic("unsupported call type opcode: " + opcode.String())
}
contract := takeAddress()
value := takeU256()
Expand Down Expand Up @@ -414,8 +415,7 @@ func newApiClosures(
captureHostio(name, args, outs, startInk, endInk)
return []byte{}, nil, 0
default:
log.Crit("unsupported call type", "req", req)
return []byte{}, nil, 0
panic("unsupported call type: " + strconv.Itoa(int(req)))
}
}
}
6 changes: 3 additions & 3 deletions arbos/programs/native_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import "C"

import (
"runtime"
"strconv"
"sync"
"sync/atomic"

"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"

"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/arbutil"
Expand Down Expand Up @@ -69,11 +69,11 @@ func newApi(
func getApi(id usize) NativeApi {
any, ok := apiObjects.Load(uintptr(id))
if !ok {
log.Crit("failed to load stylus Go API", "id", id)
panic("failed to load stylus Go API id: " + strconv.Itoa(int(id)))
}
api, ok := any.(NativeApi)
if !ok {
log.Crit("wrong type for stylus Go API", "id", id)
panic("wrong type for stylus Go API id: " + strconv.Itoa(int(id)))
}
return api
}
Expand Down
3 changes: 1 addition & 2 deletions arbos/programs/programs.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ func (p Programs) CallProgram(

localAsm, err := getLocalAsm(statedb, moduleHash, contract.Address(), contract.Code, contract.CodeHash, params.PageLimit, evm.Context.Time, debugMode, program)
if err != nil {
log.Crit("failed to get local wasm for activated program", "program", contract.Address())
return nil, err
panic("failed to get local wasm for activated program: " + contract.Address().Hex())
}

evmData := &EvmData{
Expand Down
6 changes: 3 additions & 3 deletions arbstate/inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ func parseSequencerMessage(ctx context.Context, batchNum uint64, batchBlockHash
// Matches the way keyset validation was done inside DAS readers i.e logging the error
// But other daproviders might just want to return the error
if errors.Is(err, daprovider.ErrSeqMsgValidation) && daprovider.IsDASMessageHeaderByte(payload[0]) {
logLevel := log.Error
if keysetValidationMode == daprovider.KeysetPanicIfInvalid {
logLevel = log.Crit
panic(err.Error())
} else {
log.Error(err.Error())
}
logLevel(err.Error())
} else {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions precompiles/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"

"github.com/offchainlabs/nitro/arbos"
"github.com/offchainlabs/nitro/arbos/arbosState"
Expand Down Expand Up @@ -58,7 +57,7 @@ func (c *Context) GasLeft() *uint64 {
}

func (c *Context) Restrict(err error) {
log.Crit("A metered burner was used for access-controlled work", "error", err)
panic("A metered burner was used for access-controlled work :" + err.Error())
}

func (c *Context) HandleError(err error) error {
Expand Down Expand Up @@ -88,13 +87,13 @@ func testContext(caller addr, evm mech) *Context {
}
state, err := arbosState.OpenArbosState(evm.StateDB, burn.NewSystemBurner(tracingInfo, false))
if err != nil {
log.Crit("unable to open arbos state", "error", err)
panic("unable to open arbos state :" + err.Error())
}
ctx.State = state
var ok bool
ctx.txProcessor, ok = evm.ProcessingHook.(*arbos.TxProcessor)
if !ok {
log.Crit("must have tx processor")
panic("must have tx processor")
}
return ctx
}
59 changes: 27 additions & 32 deletions precompiles/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,20 @@ func (e *SolError) Error() string {
func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Precompile) {
source, err := abi.JSON(strings.NewReader(metadata.ABI))
if err != nil {
log.Crit("Bad ABI")
panic("Bad ABI")
}

implementerType := reflect.TypeOf(implementer)
contract := implementerType.Elem().Name()

_, ok := implementerType.Elem().FieldByName("Address")
if !ok {
log.Crit("Implementer for precompile ", contract, " is missing an Address field")
panic("Implementer for precompile " + contract + " is missing an Address field")
}

address, ok := reflect.ValueOf(implementer).Elem().FieldByName("Address").Interface().(addr)
if !ok {
log.Crit("Implementer for precompile ", contract, "'s Address field has the wrong type")
panic("Implementer for precompile " + contract + "'s Address field has the wrong type")
}

gethAbiFuncTypeEquality := func(actual, geth reflect.Type) bool {
Expand Down Expand Up @@ -167,15 +167,15 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr
name = capitalize + name[1:]

if len(method.ID) != 4 {
log.Crit("Method ID isn't 4 bytes")
panic("Method ID isn't 4 bytes")
}
id := *(*[4]byte)(method.ID)

// check that the implementer has a supporting implementation for this method

handler, ok := implementerType.MethodByName(name)
if !ok {
log.Crit("Precompile " + contract + " must implement " + name)
panic("Precompile " + contract + " must implement " + name)
}

var needs = []reflect.Type{
Expand All @@ -199,7 +199,7 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr
needs = append(needs, reflect.TypeOf(&big.Int{}))
purity = payable
default:
log.Crit("Unknown state mutability ", method.StateMutability)
panic("Unknown state mutability " + method.StateMutability)
}

for _, arg := range method.Inputs {
Expand All @@ -215,10 +215,9 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr
expectedHandlerType := reflect.FuncOf(needs, outputs, false)

if !gethAbiFuncTypeEquality(handler.Type, expectedHandlerType) {
log.Crit(
"Precompile "+contract+"'s "+name+"'s implementer has the wrong type\n",
"\texpected:\t", expectedHandlerType, "\n\tbut have:\t", handler.Type,
)
panic(
"Precompile " + contract + "'s " + name + "'s implementer has the wrong type\n" +
"\texpected:\t" + expectedHandlerType.String() + "\n\tbut have:\t" + handler.Type.String())
}

method := PrecompileMethod{
Expand All @@ -237,7 +236,7 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr
method := implementerType.Method(i)
name := method.Name
if method.IsExported() && methodsByName[name] == nil {
log.Crit(contract + " is missing a solidity interface for " + name)
panic(contract + " is missing a solidity interface for " + name)
}
}

Expand Down Expand Up @@ -269,11 +268,10 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr
if arg.Indexed {
_, ok := supportedIndices[arg.Type.String()]
if !ok {
log.Crit(
"Please change the solidity for precompile ", contract,
"'s event ", name, ":\n\tEvent indices of type ",
arg.Type.String(), " are not supported",
)
panic(
"Please change the solidity for precompile " + contract +
"'s event " + name + ":\n\tEvent indices of type " +
arg.Type.String() + " are not supported")
}
}
}
Expand All @@ -288,23 +286,21 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr

field, ok := implementerType.Elem().FieldByName(name)
if !ok {
log.Crit(missing, "event ", name, " of type\n\t", expectedFieldType)
panic(missing + "event " + name + " of type\n\t" + expectedFieldType.String())
}
costField, ok := implementerType.Elem().FieldByName(name + "GasCost")
if !ok {
log.Crit(missing, "event ", name, "'s GasCost of type\n\t", expectedCostType)
panic(missing + "event " + name + "'s GasCost of type\n\t" + expectedCostType.String())
}
if !gethAbiFuncTypeEquality(field.Type, expectedFieldType) {
log.Crit(
context, "'s field for event ", name, " has the wrong type\n",
"\texpected:\t", expectedFieldType, "\n\tbut have:\t", field.Type,
)
panic(
context + "'s field for event " + name + " has the wrong type\n" +
"\texpected:\t" + expectedFieldType.String() + "\n\tbut have:\t" + field.Type.String())
}
if !gethAbiFuncTypeEquality(costField.Type, expectedCostType) {
log.Crit(
context, "'s field for event ", name, "GasCost has the wrong type\n",
"\texpected:\t", expectedCostType, "\n\tbut have:\t", costField.Type,
)
panic(
context + "'s field for event " + name + "GasCost has the wrong type\n" +
"\texpected:\t" + expectedCostType.String() + "\n\tbut have:\t" + costField.Type.String())
}

structFields := reflect.ValueOf(implementer).Elem()
Expand Down Expand Up @@ -464,13 +460,12 @@ func MakePrecompile(metadata *bind.MetaData, implementer interface{}) (addr, *Pr

field, ok := implementerType.Elem().FieldByName(name + "Error")
if !ok {
log.Crit(missing, "custom error ", name, "Error of type\n\t", expectedFieldType)
panic(missing + "custom error " + name + "Error of type\n\t" + expectedFieldType.String())
}
if field.Type != expectedFieldType {
log.Crit(
context, "'s field for error ", name, "Error has the wrong type\n",
"\texpected:\t", expectedFieldType, "\n\tbut have:\t", field.Type,
)
panic(
context + "'s field for error " + name + "Error has the wrong type\n" +
"\texpected:\t" + expectedFieldType.String() + "\n\tbut have:\t" + field.Type.String())
}

structFields := reflect.ValueOf(implementer).Elem()
Expand Down Expand Up @@ -756,7 +751,7 @@ func (p *Precompile) Call(
reflectArgs = append(reflectArgs, reflect.ValueOf(evm))
reflectArgs = append(reflectArgs, reflect.ValueOf(value))
default:
log.Crit("Unknown state mutability ", method.purity)
panic("Unknown state mutability " + strconv.Itoa(int(method.purity)))
}

args, err := method.template.Inputs.Unpack(input[4:])
Expand Down
9 changes: 0 additions & 9 deletions precompiles/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package precompiles

import (
"fmt"
"io"
"math/big"
"os"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"

"github.com/offchainlabs/nitro/arbos/storage"
Expand Down Expand Up @@ -183,12 +180,6 @@ func TestEventCosts(t *testing.T) {
}

func TestPrecompilesPerArbosVersion(t *testing.T) {
// Set up a logger in case log.Crit is called by Precompiles()
glogger := log.NewGlogHandler(
log.NewTerminalHandler(io.Writer(os.Stderr), false))
glogger.Verbosity(log.LevelWarn)
log.SetDefault(log.NewLogger(glogger))

expectedNewMethodsPerArbosVersion := map[uint64]int{
0: 89,
params.ArbosVersion_5: 3,
Expand Down
Loading

0 comments on commit b818574

Please sign in to comment.