Skip to content

Commit

Permalink
Merge branch 'master' into multi-exec-servers
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower authored May 2, 2024
2 parents 54f0674 + 58f53f9 commit 260d14a
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 52 deletions.
2 changes: 1 addition & 1 deletion arbnode/inbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestTransactionStreamer(t *testing.T) {
Fail(t, "error getting block state", err)
}
haveBalance := state.GetBalance(acct)
if balance.Cmp(haveBalance) != 0 {
if balance.Cmp(haveBalance.ToBig()) != 0 {
t.Error("unexpected balance for account", acct, "; expected", balance, "got", haveBalance)
}
}
Expand Down
15 changes: 14 additions & 1 deletion arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (state *ArbosState) UpgradeArbosVersion(
case 10:
ensure(state.l1PricingState.SetL1FeesAvailable(stateDB.GetBalance(
l1pricing.L1PricerFundsPoolAddress,
)))
).ToBig()))
case 11:
// Update the PerBatchGasCost to a more accurate value compared to the old v6 default.
ensure(state.l1PricingState.SetPerBatchGasCost(l1pricing.InitialPerBatchGasCostV12))
Expand All @@ -324,9 +324,22 @@ func (state *ArbosState) UpgradeArbosVersion(
case 20:
// Update Brotli compression level for fast compression from 0 to 1
ensure(state.SetBrotliCompressionLevel(1))
// ArbOS versions 21 through 29 are left to Orbit chains for custom upgrades.
case 30:
if !chainConfig.DebugMode() {
// This upgrade isn't finalized so we only want to support it for testing
return fmt.Errorf(
"the chain is upgrading to unsupported ArbOS version %v, %w",
nextArbosVersion,
ErrFatalNodeOutOfDate,
)
}
// no state changes needed
default:
if nextArbosVersion >= 12 && nextArbosVersion <= 19 {
// ArbOS versions 12 through 19 are left to Orbit chains for custom upgrades.
} else if nextArbosVersion >= 21 && nextArbosVersion <= 29 {
// ArbOS versions 21 through 29 are left to Orbit chains for custom upgrades.
} else {
return fmt.Errorf(
"the chain is upgrading to unsupported ArbOS version %v, %w",
Expand Down
2 changes: 1 addition & 1 deletion arbos/arbosState/initialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func checkAccounts(db *state.StateDB, arbState *ArbosState, accts []statetransfe
if db.GetNonce(addr) != acct.Nonce {
t.Fatal()
}
if db.GetBalance(addr).Cmp(acct.EthBalance) != 0 {
if db.GetBalance(addr).ToBig().Cmp(acct.EthBalance) != 0 {
t.Fatal()
}
if acct.ContractInfo != nil {
Expand Down
7 changes: 4 additions & 3 deletions arbos/arbosState/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/arbos/arbostypes"
"github.com/offchainlabs/nitro/arbos/burn"
"github.com/offchainlabs/nitro/arbos/l2pricing"
Expand Down Expand Up @@ -142,7 +143,7 @@ func InitializeArbosInDatabase(db ethdb.Database, initData statetransfer.InitDat
if err != nil {
return common.Hash{}, err
}
statedb.SetBalance(account.Addr, account.EthBalance)
statedb.SetBalance(account.Addr, uint256.MustFromBig(account.EthBalance))
statedb.SetNonce(account.Addr, account.Nonce)
if account.ContractInfo != nil {
statedb.SetCode(account.Addr, account.ContractInfo.Code)
Expand Down Expand Up @@ -173,7 +174,7 @@ func initializeRetryables(statedb *state.StateDB, rs *retryables.RetryableState,
return err
}
if r.Timeout <= currentTimestamp {
statedb.AddBalance(r.Beneficiary, r.Callvalue)
statedb.AddBalance(r.Beneficiary, uint256.MustFromBig(r.Callvalue))
continue
}
retryablesList = append(retryablesList, r)
Expand All @@ -192,7 +193,7 @@ func initializeRetryables(statedb *state.StateDB, rs *retryables.RetryableState,
addr := r.To
to = &addr
}
statedb.AddBalance(retryables.RetryableEscrowAddress(r.Id), r.Callvalue)
statedb.AddBalance(retryables.RetryableEscrowAddress(r.Id), uint256.MustFromBig(r.Callvalue))
_, err := rs.CreateRetryable(r.Id, r.Timeout, r.From, to, r.Callvalue, r.Beneficiary, r.Calldata)
if err != nil {
return err
Expand Down
21 changes: 11 additions & 10 deletions arbos/l1pricing/l1PricingOldVersions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
package l1pricing

import (
"math"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/offchainlabs/nitro/arbos/util"
am "github.com/offchainlabs/nitro/util/arbmath"
"math"
"math/big"
)

func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
Expand Down Expand Up @@ -105,8 +106,8 @@ func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
// pay rewards, as much as possible
paymentForRewards := am.BigMulByUint(am.UintToBig(perUnitReward), unitsAllocated)
availableFunds := statedb.GetBalance(L1PricerFundsPoolAddress)
if am.BigLessThan(availableFunds, paymentForRewards) {
paymentForRewards = availableFunds
if am.BigLessThan(availableFunds.ToBig(), paymentForRewards) {
paymentForRewards = availableFunds.ToBig()
}
fundsDueForRewards = am.BigSub(fundsDueForRewards, paymentForRewards)
if err := ps.SetFundsDueForRewards(fundsDueForRewards); err != nil {
Expand All @@ -130,8 +131,8 @@ func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
return err
}
balanceToTransfer := balanceDueToPoster
if am.BigLessThan(availableFunds, balanceToTransfer) {
balanceToTransfer = availableFunds
if am.BigLessThan(availableFunds.ToBig(), balanceToTransfer) {
balanceToTransfer = availableFunds.ToBig()
}
if balanceToTransfer.Sign() > 0 {
addrToPay, err := posterState.PayTo()
Expand Down Expand Up @@ -166,7 +167,7 @@ func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
if err != nil {
return err
}
surplus := am.BigSub(statedb.GetBalance(L1PricerFundsPoolAddress), am.BigAdd(totalFundsDue, fundsDueForRewards))
surplus := am.BigSub(statedb.GetBalance(L1PricerFundsPoolAddress).ToBig(), am.BigAdd(totalFundsDue, fundsDueForRewards))

inertia, err := ps.Inertia()
if err != nil {
Expand Down Expand Up @@ -230,7 +231,7 @@ func (ps *L1PricingState) _preVersion2_UpdateForBatchPosterSpending(
if err != nil {
return err
}
oldSurplus := am.BigSub(statedb.GetBalance(L1PricerFundsPoolAddress), am.BigAdd(totalFundsDue, fundsDueForRewards))
oldSurplus := am.BigSub(statedb.GetBalance(L1PricerFundsPoolAddress).ToBig(), am.BigAdd(totalFundsDue, fundsDueForRewards))

// compute allocation fraction -- will allocate updateTimeDelta/timeDelta fraction of units and funds to this update
lastUpdateTime, err := ps.LastUpdateTime()
Expand Down Expand Up @@ -280,7 +281,7 @@ func (ps *L1PricingState) _preVersion2_UpdateForBatchPosterSpending(

// allocate funds to this update
collectedSinceUpdate := statedb.GetBalance(L1PricerFundsPoolAddress)
availableFunds := am.BigDivByUint(am.BigMulByUint(collectedSinceUpdate, allocationNumerator), allocationDenominator)
availableFunds := am.BigDivByUint(am.BigMulByUint(collectedSinceUpdate.ToBig(), allocationNumerator), allocationDenominator)

// pay rewards, as much as possible
paymentForRewards := am.BigMulByUint(am.UintToBig(perUnitReward), unitsAllocated)
Expand Down Expand Up @@ -356,7 +357,7 @@ func (ps *L1PricingState) _preVersion2_UpdateForBatchPosterSpending(
if err != nil {
return err
}
surplus := am.BigSub(statedb.GetBalance(L1PricerFundsPoolAddress), am.BigAdd(totalFundsDue, fundsDueForRewards))
surplus := am.BigSub(statedb.GetBalance(L1PricerFundsPoolAddress).ToBig(), am.BigAdd(totalFundsDue, fundsDueForRewards))

inertia, err := ps.Inertia()
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions arbos/l1pricing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/arbos/l1pricing"
"github.com/offchainlabs/nitro/arbos/util"
Expand Down Expand Up @@ -171,7 +172,7 @@ func _testL1PricingFundsDue(t *testing.T, testParams *l1PricingTest, expectedRes
// create some fake collection
balanceAdded := big.NewInt(int64(testParams.fundsCollectedPerSecond * 3))
unitsAdded := testParams.unitsPerSecond * 3
evm.StateDB.AddBalance(l1pricing.L1PricerFundsPoolAddress, balanceAdded)
evm.StateDB.AddBalance(l1pricing.L1PricerFundsPoolAddress, uint256.MustFromBig(balanceAdded))
err = l1p.SetL1FeesAvailable(balanceAdded)
Require(t, err)
err = l1p.SetUnitsSinceUpdate(unitsAdded)
Expand All @@ -187,7 +188,7 @@ func _testL1PricingFundsDue(t *testing.T, testParams *l1PricingTest, expectedRes
)
Require(t, err)
rewardRecipientBalance := evm.StateDB.GetBalance(rewardAddress)
if !arbmath.BigEquals(rewardRecipientBalance, expectedResults.rewardRecipientBalance) {
if !arbmath.BigEquals(rewardRecipientBalance.ToBig(), expectedResults.rewardRecipientBalance) {
Fail(t, rewardRecipientBalance, expectedResults.rewardRecipientBalance)
}
unitsRemaining, err := l1p.UnitsSinceUpdate()
Expand All @@ -196,16 +197,16 @@ func _testL1PricingFundsDue(t *testing.T, testParams *l1PricingTest, expectedRes
Fail(t, unitsRemaining, expectedResults.unitsRemaining)
}
fundsReceived := evm.StateDB.GetBalance(firstPayTo)
if !arbmath.BigEquals(fundsReceived, expectedResults.fundsReceived) {
if !arbmath.BigEquals(fundsReceived.ToBig(), expectedResults.fundsReceived) {
Fail(t, fundsReceived, expectedResults.fundsReceived)
}
fundsStillHeld := evm.StateDB.GetBalance(l1pricing.L1PricerFundsPoolAddress)
if !arbmath.BigEquals(fundsStillHeld, expectedResults.fundsStillHeld) {
if !arbmath.BigEquals(fundsStillHeld.ToBig(), expectedResults.fundsStillHeld) {
Fail(t, fundsStillHeld, expectedResults.fundsStillHeld)
}
fundsAvail, err := l1p.L1FeesAvailable()
Require(t, err)
if fundsStillHeld.Cmp(fundsAvail) != 0 {
if fundsStillHeld.ToBig().Cmp(fundsAvail) != 0 {
Fail(t, fundsStillHeld, fundsAvail)
}
}
Expand Down
2 changes: 1 addition & 1 deletion arbos/retryables/retryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (rs *RetryableState) DeleteRetryable(id common.Hash, evm *vm.EVM, scenario
escrowAddress := RetryableEscrowAddress(id)
beneficiaryAddress := common.BytesToAddress(beneficiary[:])
amount := evm.StateDB.GetBalance(escrowAddress)
err = util.TransferBalance(&escrowAddress, &beneficiaryAddress, amount, evm, scenario, "escrow")
err = util.TransferBalance(&escrowAddress, &beneficiaryAddress, amount.ToBig(), evm, scenario, "escrow")
if err != nil {
return false, err
}
Expand Down
9 changes: 6 additions & 3 deletions arbos/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"math/big"

"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/arbos/l1pricing"

"github.com/offchainlabs/nitro/arbos/util"
Expand Down Expand Up @@ -143,7 +144,9 @@ func (p *TxProcessor) StartTxHook() (endTxNow bool, gasUsed uint64, err error, r
// We intentionally use the variant here that doesn't do tracing,
// because this transfer is represented as the outer eth transaction.
// This transfer is necessary because we don't actually invoke the EVM.
core.Transfer(evm.StateDB, from, *to, value)
// Since MintBalance already called AddBalance on `from`,
// we don't have EIP-161 concerns around not touching `from`.
core.Transfer(evm.StateDB, from, *to, uint256.MustFromBig(value))
return true, 0, nil, nil
case *types.ArbitrumInternalTx:
defer (startTracer())()
Expand Down Expand Up @@ -172,7 +175,7 @@ func (p *TxProcessor) StartTxHook() (endTxNow bool, gasUsed uint64, err error, r

// check that the user has enough balance to pay for the max submission fee
balanceAfterMint := evm.StateDB.GetBalance(tx.From)
if balanceAfterMint.Cmp(tx.MaxSubmissionFee) < 0 {
if balanceAfterMint.ToBig().Cmp(tx.MaxSubmissionFee) < 0 {
err := fmt.Errorf(
"insufficient funds for max submission fee: address %v have %v want %v",
tx.From, balanceAfterMint, tx.MaxSubmissionFee,
Expand Down Expand Up @@ -256,7 +259,7 @@ func (p *TxProcessor) StartTxHook() (endTxNow bool, gasUsed uint64, err error, r

maxGasCost := arbmath.BigMulByUint(tx.GasFeeCap, usergas)
maxFeePerGasTooLow := arbmath.BigLessThan(tx.GasFeeCap, effectiveBaseFee)
if arbmath.BigLessThan(balance, maxGasCost) || usergas < params.TxGas || maxFeePerGasTooLow {
if arbmath.BigLessThan(balance.ToBig(), maxGasCost) || usergas < params.TxGas || maxFeePerGasTooLow {
// User either specified too low of a gas fee cap, didn't have enough balance to pay for gas,
// or the specified gas limit is below the minimum transaction gas cost.
// Either way, attempt to refund the gas costs, since we're not doing the auto-redeem.
Expand Down
4 changes: 2 additions & 2 deletions arbos/util/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewTracingInfo(evm *vm.EVM, from, to common.Address, scenario TracingScenar
return &TracingInfo{
Tracer: evm.Config.Tracer,
Scenario: scenario,
Contract: vm.NewContract(addressHolder{to}, addressHolder{from}, big.NewInt(0), 0),
Contract: vm.NewContract(addressHolder{to}, addressHolder{from}, uint256.NewInt(0), 0),
Depth: evm.Depth(),
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func (info *TracingInfo) MockCall(input []byte, gas uint64, from, to common.Addr
tracer := info.Tracer
depth := info.Depth

contract := vm.NewContract(addressHolder{to}, addressHolder{from}, amount, gas)
contract := vm.NewContract(addressHolder{to}, addressHolder{from}, uint256.MustFromBig(amount), gas)

scope := &vm.ScopeContext{
Memory: TracingMemoryFromBytes(input),
Expand Down
13 changes: 9 additions & 4 deletions arbos/util/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/holiman/uint256"
"github.com/offchainlabs/nitro/util/arbmath"
)

Expand All @@ -29,13 +30,17 @@ func TransferBalance(
}
if from != nil {
balance := evm.StateDB.GetBalance(*from)
if arbmath.BigLessThan(balance, amount) {
if arbmath.BigLessThan(balance.ToBig(), amount) {
return fmt.Errorf("%w: addr %v have %v want %v", vm.ErrInsufficientBalance, *from, balance, amount)
}
evm.StateDB.SubBalance(*from, amount)
evm.StateDB.SubBalance(*from, uint256.MustFromBig(amount))
if evm.Context.ArbOSVersion >= 30 {
// ensure the from account is "touched" for EIP-161
evm.StateDB.AddBalance(*from, &uint256.Int{})
}
}
if to != nil {
evm.StateDB.AddBalance(*to, amount)
evm.StateDB.AddBalance(*to, uint256.MustFromBig(amount))
}
if tracer := evm.Config.Tracer; tracer != nil {
if evm.Depth() != 0 && scenario != TracingDuringEVM {
Expand All @@ -59,7 +64,7 @@ func TransferBalance(
info := &TracingInfo{
Tracer: evm.Config.Tracer,
Scenario: scenario,
Contract: vm.NewContract(addressHolder{*to}, addressHolder{*from}, big.NewInt(0), 0),
Contract: vm.NewContract(addressHolder{*to}, addressHolder{*from}, uint256.NewInt(0), 0),
Depth: evm.Depth(),
}
info.MockCall([]byte{}, 0, *from, *to, amount)
Expand Down
2 changes: 1 addition & 1 deletion execution/gethexec/tx_pre_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func PreCheckTx(bc *core.BlockChain, chainConfig *params.ChainConfig, header *ty
}
balance := statedb.GetBalance(sender)
cost := tx.Cost()
if arbmath.BigLessThan(balance, cost) {
if arbmath.BigLessThan(balance.ToBig(), cost) {
return fmt.Errorf("%w: address %v have %v want %v", core.ErrInsufficientFunds, sender, balance, cost)
}
if config.Strictness >= TxPreCheckerStrictnessFullValidation && tx.Nonce() > stateNonce {
Expand Down
2 changes: 1 addition & 1 deletion gethhook/geth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestEthDepositMessage(t *testing.T) {

RunMessagesThroughAPI(t, [][]byte{serialized, serialized2}, statedb)

balanceAfter := statedb.GetBalance(addr)
balanceAfter := statedb.GetBalance(addr).ToBig()
if balanceAfter.Cmp(new(big.Int).Add(balance.Big(), balance2.Big())) != 0 {
Fail(t)
}
Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
Submodule go-ethereum updated 169 files
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-redis/redis/v8 v8.11.4
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/uuid v1.3.1
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
Expand Down Expand Up @@ -2023,6 +2024,7 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
Loading

0 comments on commit 260d14a

Please sign in to comment.