Skip to content

Commit

Permalink
Merge branch 'master' into redis_sentinel
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi authored Oct 29, 2024
2 parents 51dd85b + aa6d69a commit 11f0125
Show file tree
Hide file tree
Showing 18 changed files with 1,447 additions and 58 deletions.
36 changes: 36 additions & 0 deletions .github/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 0.2

phases:
pre_build:
commands:
- git submodule update --init
- echo Logging in to Dockerhub....
- docker login --username $DOCKERHUB_USERNAME --password $DOCKERHUB_PASSWORD
- aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin $REPOSITORY_URI
- COMMIT_HASH=$(git rev-parse --short=7 HEAD || echo "latest")
- VERSION_TAG=$(git tag --points-at HEAD | sed '/-/!s/$/_/' | sort -rV | sed 's/_$//' | head -n 1 | grep ^ || git show -s --pretty=%D | sed 's/, /\n/g' | grep -v '^origin/' |grep -v '^grafted\|HEAD\|master\|main$' || echo "dev")
- NITRO_VERSION=${VERSION_TAG}-${COMMIT_HASH}
- IMAGE_TAG=${NITRO_VERSION}
- NITRO_DATETIME=$(git show -s --date=iso-strict --format=%cd)
- NITRO_MODIFIED="false"
- echo ${NITRO_VERSION} > ./.nitro-tag.txt
build:
commands:
- echo Build started on `date`
- echo Building the Docker image ${NITRO_VERSION}...
- DOCKER_BUILDKIT=1 docker build . -t nitro-node-slim --target nitro-node-slim --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- DOCKER_BUILDKIT=1 docker build . -t nitro-node --target nitro-node --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- DOCKER_BUILDKIT=1 docker build . -t nitro-node-dev --target nitro-node-dev --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- DOCKER_BUILDKIT=1 docker build . -t nitro-node-validator --target nitro-node-validator --build-arg version=$NITRO_VERSION --build-arg datetime=$NITRO_DATETIME --build-arg modified=$NITRO_MODIFIED
- docker tag nitro-node:latest $REPOSITORY_URI:$IMAGE_TAG-$ARCH_TAG
- docker tag nitro-node-slim:latest $REPOSITORY_URI:$IMAGE_TAG-slim-$ARCH_TAG
- docker tag nitro-node-dev:latest $REPOSITORY_URI:$IMAGE_TAG-dev-$ARCH_TAG
- docker tag nitro-node-validator:latest $REPOSITORY_URI:$IMAGE_TAG-validator-$ARCH_TAG
post_build:
commands:
- echo Build completed on `date`
- echo pushing to repo
- docker push $REPOSITORY_URI:$IMAGE_TAG-$ARCH_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG-slim-$ARCH_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG-dev-$ARCH_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG-validator-$ARCH_TAG
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ stylus_test_hostio-test_src = $(call get_stylus_test_rust,hostio-test)
stylus_test_wasms = $(stylus_test_keccak_wasm) $(stylus_test_keccak-100_wasm) $(stylus_test_fallible_wasm) $(stylus_test_storage_wasm) $(stylus_test_multicall_wasm) $(stylus_test_log_wasm) $(stylus_test_create_wasm) $(stylus_test_math_wasm) $(stylus_test_sdk-storage_wasm) $(stylus_test_erc20_wasm) $(stylus_test_read-return-data_wasm) $(stylus_test_evm-data_wasm) $(stylus_test_hostio-test_wasm) $(stylus_test_bfs:.b=.wasm)
stylus_benchmarks = $(wildcard $(stylus_dir)/*.toml $(stylus_dir)/src/*.rs) $(stylus_test_wasms)

CBROTLI_WASM_BUILD_ARGS ?=-d

# user targets

.PHONY: push
Expand Down Expand Up @@ -579,9 +581,9 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(prover_bin)
@touch $@

.make/cbrotli-wasm: $(DEP_PREDICATE) $(ORDER_ONLY_PREDICATE) .make
test -f target/lib-wasm/libbrotlicommon-static.a || ./scripts/build-brotli.sh -w -d
test -f target/lib-wasm/libbrotlienc-static.a || ./scripts/build-brotli.sh -w -d
test -f target/lib-wasm/libbrotlidec-static.a || ./scripts/build-brotli.sh -w -d
test -f target/lib-wasm/libbrotlicommon-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS)
test -f target/lib-wasm/libbrotlienc-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS)
test -f target/lib-wasm/libbrotlidec-static.a || ./scripts/build-brotli.sh -w $(CBROTLI_WASM_BUILD_ARGS)
@touch $@

.make/wasm-lib: $(DEP_PREDICATE) arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/softfloat.a $(ORDER_ONLY_PREDICATE) .make
Expand Down
7 changes: 6 additions & 1 deletion arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ type BatchPosterConfig struct {
Dangerous BatchPosterDangerousConfig `koanf:"dangerous"`
ReorgResistanceMargin time.Duration `koanf:"reorg-resistance-margin" reload:"hot"`
CheckBatchCorrectness bool `koanf:"check-batch-correctness"`
MaxEmptyBatchDelay time.Duration `koanf:"max-empty-batch-delay"`

gasRefunder common.Address
l1BlockBound l1BlockBound
Expand Down Expand Up @@ -224,6 +225,7 @@ func BatchPosterConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.Uint64(prefix+".gas-estimate-base-fee-multiple-bips", uint64(DefaultBatchPosterConfig.GasEstimateBaseFeeMultipleBips), "for gas estimation, use this multiple of the basefee (measured in basis points) as the max fee per gas")
f.Duration(prefix+".reorg-resistance-margin", DefaultBatchPosterConfig.ReorgResistanceMargin, "do not post batch if its within this duration from layer 1 minimum bounds. Requires l1-block-bound option not be set to \"ignore\"")
f.Bool(prefix+".check-batch-correctness", DefaultBatchPosterConfig.CheckBatchCorrectness, "setting this to true will run the batch against an inbox multiplexer and verifies that it produces the correct set of messages")
f.Duration(prefix+".max-empty-batch-delay", DefaultBatchPosterConfig.MaxEmptyBatchDelay, "maximum empty batch posting delay, batch poster will only be able to post an empty batch if this time period building a batch has passed")
redislock.AddConfigOptions(prefix+".redis-lock", f)
dataposter.DataPosterConfigAddOptions(prefix+".data-poster", f, dataposter.DefaultDataPosterConfig)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultBatchPosterConfig.ParentChainWallet.Pathname)
Expand Down Expand Up @@ -255,6 +257,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
GasEstimateBaseFeeMultipleBips: arbmath.OneInUBips * 3 / 2,
ReorgResistanceMargin: 10 * time.Minute,
CheckBatchCorrectness: true,
MaxEmptyBatchDelay: 3 * 24 * time.Hour,
}

var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{
Expand Down Expand Up @@ -1303,7 +1306,9 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
b.building.muxBackend.delayedInbox = append(b.building.muxBackend.delayedInbox, msg)
}
}
if msg.Message.Header.Kind != arbostypes.L1MessageType_BatchPostingReport {
// #nosec G115
timeSinceMsg := time.Since(time.Unix(int64(msg.Message.Header.Timestamp), 0))
if (msg.Message.Header.Kind != arbostypes.L1MessageType_BatchPostingReport) || (timeSinceMsg >= config.MaxEmptyBatchDelay) {
b.building.haveUsefulMessage = true
if b.building.firstUsefulMsg == nil {
b.building.firstUsefulMsg = msg
Expand Down
1 change: 1 addition & 0 deletions das/dasRpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (c *DASRPCClient) Store(ctx context.Context, message []byte, timeout uint64
var startChunkedStoreResult StartChunkedStoreResult
if err := c.clnt.CallContext(ctx, &startChunkedStoreResult, "das_startChunkedStore", hexutil.Uint64(timestamp), hexutil.Uint64(nChunks), hexutil.Uint64(c.chunkSize), hexutil.Uint64(totalSize), hexutil.Uint64(timeout), hexutil.Bytes(startReqSig)); err != nil {
if strings.Contains(err.Error(), "the method das_startChunkedStore does not exist") {
log.Info("Legacy store is used by the DAS client", "url", c.url)
return c.legacyStore(ctx, message, timeout)
}
return nil, err
Expand Down
12 changes: 12 additions & 0 deletions precompiles/ArbAddressTable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func TestAddressTable1(t *testing.T) {

addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20])

exists, err := atab.AddressExists(context, evm, addr)
Require(t, err)
if exists {
t.Fatal("Address shouldn't exist")
}

// register addr
slot, err := atab.Register(context, evm, addr)
Require(t, err)
Expand All @@ -61,6 +67,12 @@ func TestAddressTable1(t *testing.T) {
t.Fatal()
}

exists, err = atab.AddressExists(context, evm, addr)
Require(t, err)
if !exists {
t.Fatal("Address should exist")
}

// verify Lookup of addr returns 0
index, err := atab.Lookup(context, evm, addr)
Require(t, err)
Expand Down
28 changes: 0 additions & 28 deletions precompiles/ArbAggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,6 @@ import (
"github.com/offchainlabs/nitro/arbos/l1pricing"
)

func TestArbAggregatorBatchPosters(t *testing.T) {
evm := newMockEVMForTesting()
context := testContext(common.Address{}, evm)

addr := common.BytesToAddress(crypto.Keccak256([]byte{})[:20])

// initially should have one batch poster
bps, err := ArbAggregator{}.GetBatchPosters(context, evm)
Require(t, err)
if len(bps) != 1 {
Fail(t)
}

// add addr as a batch poster
Require(t, ArbDebug{}.BecomeChainOwner(context, evm))
Require(t, ArbAggregator{}.AddBatchPoster(context, evm, addr))

// there should now be two batch posters, and addr should be one of them
bps, err = ArbAggregator{}.GetBatchPosters(context, evm)
Require(t, err)
if len(bps) != 2 {
Fail(t)
}
if bps[0] != addr && bps[1] != addr {
Fail(t)
}
}

func TestFeeCollector(t *testing.T) {
evm := newMockEVMForTesting()
agg := ArbAggregator{}
Expand Down
140 changes: 140 additions & 0 deletions precompiles/ArbGasInfo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Copyright 2021-2024, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

package precompiles

import (
"math/big"
"testing"

"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/crypto"
"github.com/ethereum/go-ethereum/params"
"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/arbos/burn"
"github.com/offchainlabs/nitro/arbos/storage"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/util/testhelpers"
)

func setupArbGasInfo(
t *testing.T,
) (
*vm.EVM,
*arbosState.ArbosState,
*Context,
*ArbGasInfo,
) {
evm := newMockEVMForTesting()
caller := common.BytesToAddress(crypto.Keccak256([]byte{})[:20])
tracer := util.NewTracingInfo(evm, testhelpers.RandomAddress(), types.ArbosAddress, util.TracingDuringEVM)
state, err := arbosState.OpenArbosState(evm.StateDB, burn.NewSystemBurner(tracer, false))
Require(t, err)

arbGasInfo := &ArbGasInfo{}
callCtx := testContext(caller, evm)

return evm, state, callCtx, arbGasInfo
}

func TestGetGasBacklog(t *testing.T) {
t.Parallel()

evm, state, callCtx, arbGasInfo := setupArbGasInfo(t)

backlog := uint64(1000)
err := state.L2PricingState().SetGasBacklog(backlog)
Require(t, err)
retrievedBacklog, err := arbGasInfo.GetGasBacklog(callCtx, evm)
Require(t, err)
if retrievedBacklog != backlog {
t.Fatal("expected backlog to be", backlog, "but got", retrievedBacklog)
}
}

func TestGetL1PricingUpdateTime(t *testing.T) {
t.Parallel()

evm, state, callCtx, arbGasInfo := setupArbGasInfo(t)

lastUpdateTime := uint64(1001)
err := state.L1PricingState().SetLastUpdateTime(lastUpdateTime)
Require(t, err)
retrievedLastUpdateTime, err := arbGasInfo.GetLastL1PricingUpdateTime(callCtx, evm)
Require(t, err)
if retrievedLastUpdateTime != lastUpdateTime {
t.Fatal("expected last update time to be", lastUpdateTime, "but got", retrievedLastUpdateTime)
}
}

func TestGetL1PricingFundsDueForRewards(t *testing.T) {
t.Parallel()

evm, state, callCtx, arbGasInfo := setupArbGasInfo(t)

fundsDueForRewards := big.NewInt(1002)
err := state.L1PricingState().SetFundsDueForRewards(fundsDueForRewards)
Require(t, err)
retrievedFundsDueForRewards, err := arbGasInfo.GetL1PricingFundsDueForRewards(callCtx, evm)
Require(t, err)
if retrievedFundsDueForRewards.Cmp(fundsDueForRewards) != 0 {
t.Fatal("expected funds due for rewards to be", fundsDueForRewards, "but got", retrievedFundsDueForRewards)
}
}

func TestGetL1PricingUnitsSinceUpdate(t *testing.T) {
t.Parallel()

evm, state, callCtx, arbGasInfo := setupArbGasInfo(t)

pricingUnitsSinceUpdate := uint64(1003)
err := state.L1PricingState().SetUnitsSinceUpdate(pricingUnitsSinceUpdate)
Require(t, err)
retrievedPricingUnitsSinceUpdate, err := arbGasInfo.GetL1PricingUnitsSinceUpdate(callCtx, evm)
Require(t, err)
if retrievedPricingUnitsSinceUpdate != pricingUnitsSinceUpdate {
t.Fatal("expected pricing units since update to be", pricingUnitsSinceUpdate, "but got", retrievedPricingUnitsSinceUpdate)
}
}

func TestGetLastL1PricingSurplus(t *testing.T) {
t.Parallel()

evm, state, callCtx, arbGasInfo := setupArbGasInfo(t)

lastSurplus := big.NewInt(1004)
err := state.L1PricingState().SetLastSurplus(lastSurplus, params.ArbosVersion_Stylus)
Require(t, err)
retrievedLastSurplus, err := arbGasInfo.GetLastL1PricingSurplus(callCtx, evm)
Require(t, err)
if retrievedLastSurplus.Cmp(lastSurplus) != 0 {
t.Fatal("expected last surplus to be", lastSurplus, "but got", retrievedLastSurplus)
}
}

func TestGetPricesInArbGas(t *testing.T) {
t.Parallel()

evm := newMockEVMForTesting()
caller := common.BytesToAddress(crypto.Keccak256([]byte{})[:20])
arbGasInfo := &ArbGasInfo{}
callCtx := testContext(caller, evm)

evm.Context.BaseFee = big.NewInt(1005)
expectedGasPerL2Tx := big.NewInt(111442786069)
expectedGasForL1Calldata := big.NewInt(796019900)
expectedStorageArbGas := big.NewInt(int64(storage.StorageWriteCost))
gasPerL2Tx, gasForL1Calldata, storageArbGas, err := arbGasInfo.GetPricesInArbGas(callCtx, evm)
Require(t, err)
if gasPerL2Tx.Cmp(expectedGasPerL2Tx) != 0 {
t.Fatal("expected gas per L2 tx to be", expectedGasPerL2Tx, "but got", gasPerL2Tx)
}
if gasForL1Calldata.Cmp(expectedGasForL1Calldata) != 0 {
t.Fatal("expected gas for L1 calldata to be", expectedGasForL1Calldata, "but got", gasForL1Calldata)
}
if storageArbGas.Cmp(expectedStorageArbGas) != 0 {
t.Fatal("expected storage arb gas to be", expectedStorageArbGas, "but got", storageArbGas)
}
}
17 changes: 17 additions & 0 deletions precompiles/ArbOwner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ func TestArbOwner(t *testing.T) {
if avail.Cmp(deposited) != 0 {
Fail(t, avail, deposited)
}

err = prec.SetNetworkFeeAccount(callCtx, evm, addr1)
Require(t, err)
retrievedNetworkFeeAccount, err := prec.GetNetworkFeeAccount(callCtx, evm)
Require(t, err)
if retrievedNetworkFeeAccount.Cmp(addr1) != 0 {
Fail(t, "Expected", addr1, "got", retrievedNetworkFeeAccount)
}

l2BaseFee := big.NewInt(123)
err = prec.SetL2BaseFee(callCtx, evm, l2BaseFee)
Require(t, err)
retrievedL2BaseFee, err := state.L2PricingState().BaseFeeWei()
Require(t, err)
if l2BaseFee.Cmp(retrievedL2BaseFee) != 0 {
Fail(t, "Expected", l2BaseFee, "got", retrievedL2BaseFee)
}
}

func TestArbOwnerSetChainConfig(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion precompiles/ArbRetryableTx.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func (con ArbRetryableTx) GetTimeout(c ctx, evm mech, ticketId bytes32) (huge, e

// Keepalive adds one lifetime period to the ticket's expiry
func (con ArbRetryableTx) Keepalive(c ctx, evm mech, ticketId bytes32) (huge, error) {

// charge for the expiry update
retryableState := c.State.RetryableState()
nbytes, err := retryableState.RetryableSizeBytes(ticketId, evm.Context.Time)
Expand Down
25 changes: 25 additions & 0 deletions precompiles/ArbRetryableTx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,37 @@ import (
"math/big"
"testing"

"github.com/offchainlabs/nitro/arbos"
"github.com/offchainlabs/nitro/arbos/storage"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm"
templates "github.com/offchainlabs/nitro/solgen/go/precompilesgen"
)

func newMockEVMForTestingWithCurrentRefundTo(currentRefundTo *common.Address) *vm.EVM {
evm := newMockEVMForTesting()
txProcessor := arbos.NewTxProcessor(evm, &core.Message{})
txProcessor.CurrentRefundTo = currentRefundTo
evm.ProcessingHook = txProcessor
return evm
}

func TestGetCurrentRedeemer(t *testing.T) {
currentRefundTo := common.HexToAddress("0x030405")

evm := newMockEVMForTestingWithCurrentRefundTo(&currentRefundTo)
retryableTx := ArbRetryableTx{}
context := testContext(common.Address{}, evm)

currentRedeemer, err := retryableTx.GetCurrentRedeemer(context, evm)
Require(t, err)
if currentRefundTo.Cmp(currentRedeemer) != 0 {
t.Fatal("Expected to be ", currentRefundTo, " but got ", currentRedeemer)
}
}

func TestRetryableRedeem(t *testing.T) {
evm := newMockEVMForTesting()
precompileCtx := testContext(common.Address{}, evm)
Expand Down
1 change: 0 additions & 1 deletion precompiles/ArbSys.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func (con *ArbSys) WasMyCallersAddressAliased(c ctx, evm mech) (bool, error) {

// MyCallersAddressWithoutAliasing gets the caller's caller without any potential aliasing
func (con *ArbSys) MyCallersAddressWithoutAliasing(c ctx, evm mech) (addr, error) {

address := addr{}

if evm.Depth() > 1 {
Expand Down
3 changes: 2 additions & 1 deletion pubsub/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ func (p *Producer[Request, Response]) clearMessages(ctx context.Context) time.Du
}
if _, err := p.client.XDel(ctx, p.redisStream, pelData.Lower).Result(); err != nil {
log.Error("error deleting PEL's lower message thats past its TTL", "msgID", pelData.Lower, "err", err)
return 0
return 5 * p.cfg.CheckResultInterval
}
return 0
}
}
return 5 * p.cfg.CheckResultInterval
Expand Down
Loading

0 comments on commit 11f0125

Please sign in to comment.