Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive expired retryables #1660

Draft
wants to merge 56 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9e76943
add rough draft of accumulating expired retryables
magicxyyz May 23, 2023
9764d2c
add packed set skeleton
magicxyyz May 23, 2023
c9fb42f
use also retryable id when getting retrayable hash
magicxyyz May 24, 2023
b0747d7
add storage backed Uint64Set
magicxyyz May 24, 2023
56a8da9
add checkValidArchivedAndRedeemable, track nonredeemable instead of r…
magicxyyz May 26, 2023
6def19a
add moveFundsLeftInEscrowToBeneficiary helper
magicxyyz May 30, 2023
453905f
draft RedeemArchived
magicxyyz May 31, 2023
deab4dc
pass retryable data in RedeemArchivedScheduledEvent
magicxyyz Jun 2, 2023
9f22086
revert some changes
magicxyyz Jun 2, 2023
5efb550
add ArbRetryableTx Revive method in place of RedeemArchive / CancelAr…
magicxyyz Jun 5, 2023
b14b235
emit ExpiredMerkleUpdate event
magicxyyz Jun 7, 2023
3858e12
update contracts
magicxyyz Jun 7, 2023
b57c2f5
Merge branch 'master' into expired-retryables
magicxyyz Jun 7, 2023
eabc366
revert state if reaping retryable fails
magicxyyz Jun 8, 2023
25f7a73
update contracts
magicxyyz Jun 8, 2023
4e0f6ba
emit RetryableExpired event
magicxyyz Jun 15, 2023
26927b9
Merge branch 'master' into expired-retryables
magicxyyz Jun 15, 2023
e1eca08
update contracts
magicxyyz Jun 15, 2023
86b74b2
fix RetryableExpired event emitting loop
magicxyyz Jun 15, 2023
3d5e8de
update contracts
magicxyyz Jun 15, 2023
637aa15
fix emited expired retryable leaf position, add revival unit test draft
magicxyyz Jun 20, 2023
91e5849
fix lint
magicxyyz Jun 20, 2023
aefa2e8
update contracts
magicxyyz Jun 21, 2023
d3b70fd
Merge branch 'master' into expired-retryables
magicxyyz Jun 21, 2023
32ff10d
add draft of expired retryable revival system test
magicxyyz Jun 28, 2023
c61427f
update contracts
magicxyyz Jun 28, 2023
1ae6a88
clean up debug logs
magicxyyz Jun 28, 2023
83157f8
further refactor system test for retryable revival
magicxyyz Jun 29, 2023
b8a535f
fix NewLevelAndLeafFromPostion, add more system tests for retryable r…
magicxyyz Jun 30, 2023
c67a087
update contracts
magicxyyz Jun 30, 2023
5c1c78b
fix ArbRetryableTx.toSolidityError
magicxyyz Jun 30, 2023
3bb3ce0
extend retryable revival system test
magicxyyz Jun 30, 2023
33218e3
update contracts
magicxyyz Jun 30, 2023
6d1d231
Merge branch 'master' into expired-retryables
magicxyyz Jul 5, 2023
9fada80
add ring buffer
magicxyyz Jul 7, 2023
8302345
add expired merkle root snapshots
magicxyyz Jul 7, 2023
0abecc0
Merge branch 'master' into expired-retryables
magicxyyz Jul 7, 2023
9de9e40
update contracts
magicxyyz Jul 7, 2023
1b555d1
fix conditionaltx system test
magicxyyz Jul 7, 2023
aaab63f
extend retryable revival system test
magicxyyz Jul 11, 2023
f54055a
retryables unit test: add expected state check after expiry
magicxyyz Jul 11, 2023
0678059
Merge branch 'master' into expired-retryables
magicxyyz Jul 11, 2023
78a5da9
update contracts
magicxyyz Jul 11, 2023
fe76152
add state check in retryable cleanup test
magicxyyz Jul 11, 2023
8edc704
add missing error checks in retryable unit tests
magicxyyz Jul 11, 2023
6f65365
update contracts
magicxyyz Jul 11, 2023
1fb74c7
remove timestamp from ExpiredMerkleRootSnapshot event
magicxyyz Jul 12, 2023
6e018aa
use getLastExpiredRootSnapshot method instead of getting ExpiredMerkl…
magicxyyz Jul 13, 2023
37f745f
wrap RingBuffer in MerkleRootSnapshots
magicxyyz Jul 13, 2023
b635958
update contracts
magicxyyz Sep 11, 2023
b51b922
Merge branch 'master' into expired-retryables
magicxyyz Sep 11, 2023
8f75aad
Merge branch 'master' into expired-retryables
magicxyyz Sep 15, 2023
9305718
improve key locality in Uint64Set
magicxyyz Sep 15, 2023
0db7295
refactor ring buffer
magicxyyz Sep 19, 2023
9e76518
Merge branch 'master' into expired-retryables
magicxyyz Sep 19, 2023
b6f2190
Merge branch 'master' into expired-retryables
magicxyyz Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arbos/arbosState/arbosstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func OpenArbosState(stateDB vm.StateDB, burner burn.Burner) (*ArbosState, error)
backingStorage.OpenStorageBackedAddress(uint64(networkFeeAccountOffset)),
l1pricing.OpenL1PricingState(backingStorage.OpenSubStorage(l1PricingSubspace)),
l2pricing.OpenL2PricingState(backingStorage.OpenSubStorage(l2PricingSubspace)),
retryables.OpenRetryableState(backingStorage.OpenSubStorage(retryablesSubspace), stateDB),
retryables.OpenRetryableState(backingStorage.OpenSubStorage(retryablesSubspace)),
addressTable.Open(backingStorage.OpenSubStorage(addressTableSubspace)),
addressSet.OpenAddressSet(backingStorage.OpenSubStorage(chainOwnerSubspace)),
merkleAccumulator.OpenMerkleAccumulator(backingStorage.OpenSubStorage(sendMerkleSubspace)),
Expand Down
8 changes: 7 additions & 1 deletion arbos/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ var ArbSysAddress common.Address
var InternalTxStartBlockMethodID [4]byte
var InternalTxBatchPostingReportMethodID [4]byte
var RedeemScheduledEventID common.Hash
var ExpiredMerkleUpdateEventID common.Hash
var ExpiredMerkleRootSnapshotEventID common.Hash
var RetryableExpiredEventID common.Hash
var L2ToL1TransactionEventID common.Hash
var L2ToL1TxEventID common.Hash
var EmitReedeemScheduledEvent func(*vm.EVM, uint64, uint64, [32]byte, [32]byte, common.Address, *big.Int, *big.Int) error
var EmitTicketCreatedEvent func(*vm.EVM, [32]byte) error
var EmitExpiredMerkleUpdateEvent func(*vm.EVM, [32]byte, *big.Int) error
var EmitExpiredMerkleRootSnapshotEvent func(*vm.EVM, [32]byte, uint64) error
var EmitRetryableExpiredEvent func(*vm.EVM, [32]byte, *big.Int, [32]byte, uint64) error
var gasUsedSinceStartupCounter = metrics.NewRegisteredCounter("arb/gas_used", nil)

type L1Info struct {
Expand Down Expand Up @@ -230,7 +236,7 @@ func ProduceBlockAdvanced(
}
retryable, _ := state.RetryableState().OpenRetryable(retry.TicketId, time)
if retryable == nil {
// retryable was already deleted
// retryable expired or was canceled
continue
}
} else {
Expand Down
41 changes: 38 additions & 3 deletions arbos/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/big"

"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/merkletree"

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

Expand Down Expand Up @@ -82,9 +83,43 @@ func ApplyInternalTxUpdate(tx *types.ArbitrumInternalTx, state *arbosState.Arbos

currentTime := evm.Context.Time

// Try to reap 2 retryables
_ = state.RetryableState().TryToReapOneRetryable(currentTime, evm, util.TracingDuringEVM)
_ = state.RetryableState().TryToReapOneRetryable(currentTime, evm, util.TracingDuringEVM)
// Try to reap 2 retryables, revert the state on failure
snapshot := evm.StateDB.Snapshot()
reapingLoop:
for i := 0; i < 2; i++ {
merkleUpdateEvents, leaf, err := state.RetryableState().TryToReapOneRetryable(currentTime, evm, util.TracingDuringEVM)
if err != nil {
log.Error("Failed to try reaping one retryable", "err", err)
break
}
if leaf != nil {
position := merkletree.LevelAndLeaf{Level: 0, Leaf: leaf.Index}
if err = EmitRetryableExpiredEvent(evm, leaf.Hash, position.ToBigInt(), leaf.TicketId, leaf.NumTries); err != nil {
log.Error("Failed to emit RetryableExpired event", "err", err)
break
}
}
for _, event := range merkleUpdateEvents {
position := merkletree.LevelAndLeaf{Level: event.Level, Leaf: event.NumLeaves}
if err = EmitExpiredMerkleUpdateEvent(evm, event.Hash, position.ToBigInt()); err != nil {
log.Error("Failed to emit ExpiredMerkleUpdate event", "err", err)
break reapingLoop
}
}
// we succeeded reaping, so take new snapshot
snapshot = evm.StateDB.Snapshot()
}
if err == nil {
err := state.RetryableState().TryRotatingExpiredRootSnapshots(currentTime)
if err != nil {
log.Error("Failed to try rotating expired root snapshots", "err", err)
}
}

if err != nil {
evm.StateDB.RevertToSnapshot(snapshot)
log.Warn("Reverting ticket handling because of an error (fully or partially)")
}

state.L2PricingState().UpdatePricingModel(l2BaseFee, timePassed, false)

Expand Down
2 changes: 1 addition & 1 deletion arbos/l1pricing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func TestUpdateTimeUpgradeBehavior(t *testing.T) {
if !ok {
panic("not a statedb")
}
stateCheck(t, statedb, false, "uh oh, nothing should have happened", func() {
stateCheck(t, statedb, statedb, false, "uh oh, nothing should have happened", func() {
Require(t, l1p.UpdateForBatchPosterSpending(
evm.StateDB, evm, 1, 1, 1, poster, common.Big1, amount, util.TracingDuringEVM,
))
Expand Down
14 changes: 7 additions & 7 deletions arbos/merkleAccumulator/merkleAccumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func (acc *MerkleAccumulator) setPartial(level uint64, val *common.Hash) error {
}

// Note: itemHash is hashed before being included in the tree, to prevent confusing leafs with branches.
func (acc *MerkleAccumulator) Append(itemHash common.Hash) ([]MerkleTreeNodeEvent, error) {
func (acc *MerkleAccumulator) Append(itemHash common.Hash) ([]MerkleTreeNodeEvent, uint64, error) {
size, err := acc.size.Increment()
if err != nil {
return nil, err
return nil, 0, err
}
events := []MerkleTreeNodeEvent{}

Expand All @@ -134,25 +134,25 @@ func (acc *MerkleAccumulator) Append(itemHash common.Hash) ([]MerkleTreeNodeEven
if level == CalcNumPartials(size-1) { // -1 to counteract the acc.size++ at top of this function
h := common.BytesToHash(soFar)
err := acc.setPartial(level, &h)
return events, err
return events, size, err
}
thisLevel, err := acc.getPartial(level)
if err != nil {
return nil, err
return nil, size, err
}
if *thisLevel == (common.Hash{}) {
h := common.BytesToHash(soFar)
err := acc.setPartial(level, &h)
return events, err
return events, size, err
}
soFar, err = acc.Keccak(thisLevel.Bytes(), soFar)
if err != nil {
return nil, err
return nil, size, err
}
h := common.Hash{}
err = acc.setPartial(level, &h)
if err != nil {
return nil, err
return nil, size, err
}
level += 1
events = append(events, MerkleTreeNodeEvent{level, size - 1, common.BytesToHash(soFar)})
Expand Down
Loading
Loading