Skip to content

Commit

Permalink
Merge branch 'master' into pubsub_Error
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz authored Nov 22, 2024
2 parents cfcbdaf + 288a285 commit fb241d0
Show file tree
Hide file tree
Showing 305 changed files with 1,554 additions and 796 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
enable:
- asciicheck # check for non-ascii characters
- errorlint # enure error wrapping is safely done
- gci # keep imports sorted deterministically
- gocritic # check for certain simplifications
- gofmt # ensure code is formatted
- gosec # check for security concerns
Expand All @@ -30,6 +31,13 @@ linters-settings:
#
check-type-assertions: true

gci:
sections:
- standard
- default
- prefix(github.com/ethereum/go-ethereum)
- prefix(github.com/offchainlabs)

gocritic:
disabled-tags:
- experimental
Expand Down
1 change: 1 addition & 0 deletions arbcompress/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package arbcompress
#include "arbitrator.h"
*/
import "C"

import (
"errors"
"fmt"
Expand Down
8 changes: 4 additions & 4 deletions arbitrator/bench/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use prover::prepare::prepare_machine;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Path to a preimages text file
/// Path to a preimages json file
#[arg(short, long)]
preimages_path: PathBuf,
json_inputs: PathBuf,

/// Path to a machine.wavm.br
#[arg(short, long)]
machine_path: PathBuf,
binary: PathBuf,
}

fn main() -> eyre::Result<()> {
Expand All @@ -33,7 +33,7 @@ fn main() -> eyre::Result<()> {

println!("Running benchmark with always merkleize feature on");
for step_size in step_sizes {
let mut machine = prepare_machine(args.preimages_path.clone(), args.machine_path.clone())?;
let mut machine = prepare_machine(args.json_inputs.clone(), args.binary.clone())?;
let _ = machine.hash();
let mut hash_times = vec![];
let mut step_times = vec![];
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/test-cases/dynamic.wat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

;; WAVM Module hash
(data (i32.const 0x000)
"\a1\49\cf\81\13\ff\9c\95\f2\c8\c2\a1\42\35\75\36\7d\e8\6d\d4\22\d8\71\14\bb\9e\a4\7b\af\53\5d\d7") ;; user
"\ae\87\91\cf\6a\c4\55\ff\28\06\b9\55\d5\a7\36\e8\1b\c7\91\f7\93\8a\22\a4\08\23\25\16\37\01\48\25") ;; user
(func $start (local $user i32) (local $internals i32)
;; link in user.wat
i32.const 0
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/test-cases/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const BYTES_PER_FIELD_ELEMENT = 32

var BLS_MODULUS, _ = new(big.Int).SetString("52435875175126190479447740508185965837690552500527637822603658699938581184513", 10)

var stylusModuleHash = common.HexToHash("a149cf8113ff9c95f2c8c2a1423575367de86dd422d87114bb9ea47baf535dd7") // user.wat
var stylusModuleHash = common.HexToHash("ae8791cf6ac455ff2806b955d5a736e81bc791f7938a22a40823251637014825") // user.wat

func callStylusProgram(recurse int) {
evmData := programs.EvmData{}
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/test-cases/link.wat
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(data (i32.const 0x140)
"\47\f7\4f\9c\21\51\4f\52\24\ea\d3\37\5c\bf\a9\1b\1a\5f\ef\22\a5\2a\60\30\c5\52\18\90\6b\b1\51\e5") ;; iops
(data (i32.const 0x160)
"\a1\49\cf\81\13\ff\9c\95\f2\c8\c2\a1\42\35\75\36\7d\e8\6d\d4\22\d8\71\14\bb\9e\a4\7b\af\53\5d\d7") ;; user
"\ae\87\91\cf\6a\c4\55\ff\28\06\b9\55\d5\a7\36\e8\1b\c7\91\f7\93\8a\22\a4\08\23\25\16\37\01\48\25") ;; user
(data (i32.const 0x180)
"\ee\47\08\f6\47\b2\10\88\1f\89\86\e7\e3\79\6b\b2\77\43\f1\4e\ee\cf\45\4a\9b\7c\d7\c4\5b\63\b6\d7") ;; return

Expand Down
12 changes: 12 additions & 0 deletions arbitrator/prover/test-cases/user.wat
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
i32.const 0xFFFFFF
i32.load
)
(func $infinite_loop (result i32)
(loop $loop
br $loop
)
unreachable
)
(func (export "user_entrypoint") (param $args_len i32) (result i32)
;; this func uses $args_len to select which func to call

Expand All @@ -43,6 +49,12 @@
(then (call $out_of_bounds) (return))
)

;; reverts due to an out-of-gas error
(i32.eq (local.get $args_len) (i32.const 4))
(if
(then (call $infinite_loop) (return))
)

(i32.eq (local.get $args_len) (i32.const 32))
(if
(then (call $storage_load) (return))
Expand Down
33 changes: 33 additions & 0 deletions arbitrator/stylus/tests/hostio-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,37 @@ impl HostioTest {
fn tx_origin() -> Result<Address> {
Ok(tx::origin())
}

fn storage_cache_bytes32() {
let key = B256::ZERO;
let val = B256::ZERO;
unsafe {
hostio::storage_cache_bytes32(key.as_ptr(), val.as_ptr());
}
}

fn pay_for_memory_grow(pages: U256) {
let pages: u16 = pages.try_into().unwrap();
unsafe {
hostio::pay_for_memory_grow(pages);
}
}

fn write_result_empty() {
}

fn write_result(size: U256) -> Result<Vec<u32>> {
let size: usize = size.try_into().unwrap();
let data = vec![0; size];
Ok(data)
}

fn read_args_no_args() {
}

fn read_args_one_arg(_arg1: U256) {
}

fn read_args_three_args(_arg1: U256, _arg2: U256, _arg3: U256) {
}
}
2 changes: 1 addition & 1 deletion arbitrator/wasm-libraries/user-host-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ pub trait UserHost<DR: DataReader>: GasMeteredMachine {
fn pay_for_memory_grow(&mut self, pages: u16) -> Result<(), Self::Err> {
if pages == 0 {
self.buy_ink(HOSTIO_INK)?;
return Ok(());
return trace!("pay_for_memory_grow", self, be!(pages), &[]);
}
let gas_cost = self.evm_api().add_pages(pages); // no sentry needed since the work happens after the hostio
self.buy_gas(gas_cost)?;
Expand Down
1 change: 1 addition & 0 deletions arbnode/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethdb"

"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/validator"
Expand Down
11 changes: 8 additions & 3 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,15 @@ func (c *BatchPosterConfig) Validate() error {

type BatchPosterConfigFetcher func() *BatchPosterConfig

func DangerousBatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".allow-posting-first-batch-when-sequencer-message-count-mismatch", DefaultBatchPosterConfig.Dangerous.AllowPostingFirstBatchWhenSequencerMessageCountMismatch, "allow posting the first batch even if sequence number doesn't match chain (useful after force-inclusion)")
}

func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Bool(prefix+".enable", DefaultBatchPosterConfig.Enable, "enable posting batches to l1")
f.Bool(prefix+".disable-dap-fallback-store-data-on-chain", DefaultBatchPosterConfig.DisableDapFallbackStoreDataOnChain, "If unable to batch to DA provider, disable fallback storing data on chain")
f.Int(prefix+".max-size", DefaultBatchPosterConfig.MaxSize, "maximum batch size")
f.Int(prefix+".max-4844-batch-size", DefaultBatchPosterConfig.Max4844BatchSize, "maximum 4844 blob enabled batch size")
f.Int(prefix+".max-size", DefaultBatchPosterConfig.MaxSize, "maximum estimated compressed batch size")
f.Int(prefix+".max-4844-batch-size", DefaultBatchPosterConfig.Max4844BatchSize, "maximum estimated compressed 4844 blob enabled batch size")
f.Duration(prefix+".max-delay", DefaultBatchPosterConfig.MaxDelay, "maximum batch posting delay")
f.Bool(prefix+".wait-for-max-delay", DefaultBatchPosterConfig.WaitForMaxDelay, "wait for the max batch delay, even if the batch is full")
f.Duration(prefix+".poll-interval", DefaultBatchPosterConfig.PollInterval, "how long to wait after no batches are ready to be posted before checking again")
Expand All @@ -229,6 +233,7 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
redislock.AddConfigOptions(prefix+".redis-lock", f)
dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f, dataposter.DefaultDataPosterConfig)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.ParentChainWallet.Pathname)
DangerousBatchPosterConfigAddOptions(prefix+".dangerous", f)
}

var DefaultBatchPosterConfig = BatchPosterConfig{
Expand Down Expand Up @@ -280,7 +285,7 @@ var TestBatchPosterConfig = BatchPosterConfig{
DASRetentionPeriod: daprovider.DefaultDASRetentionPeriod,
GasRefunderAddress: "",
ExtraBatchGas: 10_000,
Post4844Blobs: true,
Post4844Blobs: false,
IgnoreBlobPrice: false,
DataPoster: dataposter.TestDataPosterConfig,
ParentChainWallet: DefaultBatchPosterL1WalletConfig,
Expand Down
25 changes: 17 additions & 8 deletions arbnode/dataposter/data_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ import (
"time"

"github.com/Knetic/govaluate"
"github.com/holiman/uint256"
"github.com/redis/go-redis/v9"
"github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -34,9 +39,10 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/holiman/uint256"

"github.com/offchainlabs/nitro/arbnode/dataposter/dbstorage"
"github.com/offchainlabs/nitro/arbnode/dataposter/noop"
redisstorage "github.com/offchainlabs/nitro/arbnode/dataposter/redis"
"github.com/offchainlabs/nitro/arbnode/dataposter/slice"
"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
"github.com/offchainlabs/nitro/util/arbmath"
Expand All @@ -45,10 +51,6 @@ import (
"github.com/offchainlabs/nitro/util/rpcclient"
"github.com/offchainlabs/nitro/util/signature"
"github.com/offchainlabs/nitro/util/stopwaiter"
"github.com/redis/go-redis/v9"
"github.com/spf13/pflag"

redisstorage "github.com/offchainlabs/nitro/arbnode/dataposter/redis"
)

var (
Expand Down Expand Up @@ -1087,7 +1089,7 @@ func (p *DataPoster) updateBalance(ctx context.Context) error {
return nil
}

const maxConsecutiveIntermittentErrors = 10
const maxConsecutiveIntermittentErrors = 20

func (p *DataPoster) maybeLogError(err error, tx *storage.QueuedTransaction, msg string) {
nonce := tx.FullTx.Nonce()
Expand All @@ -1096,10 +1098,17 @@ func (p *DataPoster) maybeLogError(err error, tx *storage.QueuedTransaction, msg
return
}
logLevel := log.Error
if errors.Is(err, storage.ErrStorageRace) {
isStorageRace := errors.Is(err, storage.ErrStorageRace)
if isStorageRace || strings.Contains(err.Error(), txpool.ErrFutureReplacePending.Error()) {
p.errorCount[nonce]++
if p.errorCount[nonce] <= maxConsecutiveIntermittentErrors {
logLevel = log.Debug
if isStorageRace {
logLevel = log.Debug
} else {
logLevel = log.Info
}
} else if isStorageRace {
logLevel = log.Warn
}
} else {
delete(p.errorCount, nonce)
Expand Down
6 changes: 4 additions & 2 deletions arbnode/dataposter/dataposter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"time"

"github.com/Knetic/govaluate"
"github.com/google/go-cmp/cmp"
"github.com/holiman/uint256"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -17,8 +20,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/google/go-cmp/cmp"
"github.com/holiman/uint256"

"github.com/offchainlabs/nitro/arbnode/dataposter/externalsignertest"
"github.com/offchainlabs/nitro/util/arbmath"
)
Expand Down
1 change: 1 addition & 0 deletions arbnode/dataposter/dbstorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strconv"

"github.com/ethereum/go-ethereum/ethdb"

"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
"github.com/offchainlabs/nitro/util/dbutil"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/signer/core/apitypes"

"github.com/offchainlabs/nitro/util/testhelpers"
)

Expand Down
3 changes: 2 additions & 1 deletion arbnode/dataposter/redis/redisstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"errors"
"fmt"

"github.com/redis/go-redis/v9"

"github.com/offchainlabs/nitro/arbnode/dataposter/storage"
"github.com/offchainlabs/nitro/util/signature"
"github.com/redis/go-redis/v9"
)

// Storage implements redis sorted set backed storage. It does not support
Expand Down
1 change: 1 addition & 0 deletions arbnode/dataposter/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"

"github.com/offchainlabs/nitro/arbutil"
)

Expand Down
6 changes: 4 additions & 2 deletions arbnode/dataposter/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"path"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/offchainlabs/nitro/arbnode/dataposter/dbstorage"
"github.com/offchainlabs/nitro/arbnode/dataposter/redis"
"github.com/offchainlabs/nitro/arbnode/dataposter/slice"
Expand Down
6 changes: 5 additions & 1 deletion arbnode/delayed.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ func (b *DelayedBridge) parseMessage(ctx context.Context, ethLog types.Log) (*bi
if err != nil {
return nil, nil, err
}
return parsedLog.MessageNum, args["messageData"].([]byte), nil
dataBytes, ok := args["messageData"].([]byte)
if !ok {
return nil, nil, errors.New("messageData not a byte array")
}
return parsedLog.MessageNum, dataBytes, nil
default:
return nil, nil, errors.New("unexpected log type")
}
Expand Down
1 change: 1 addition & 0 deletions arbnode/delayed_seq_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/solgen/go/bridgegen"
)
Expand Down
3 changes: 2 additions & 1 deletion arbnode/delayed_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"math/big"
"sync"

flag "github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
flag "github.com/spf13/pflag"

"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/execution"
Expand Down
3 changes: 2 additions & 1 deletion arbnode/inbox_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
"sync/atomic"
"time"

flag "github.com/spf13/pflag"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
flag "github.com/spf13/pflag"

"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/util/arbmath"
Expand Down
Loading

0 comments on commit fb241d0

Please sign in to comment.