Skip to content

Commit

Permalink
Properly support replace by fee for the data poster (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Feb 28, 2024
1 parent 5dab604 commit 20651e7
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 59 deletions.
168 changes: 127 additions & 41 deletions arbnode/dataposter/data_poster.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions arbnode/dataposter/dbstorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ func (s *Storage) FetchContents(_ context.Context, startingIndex uint64, maxResu
return res, it.Error()
}

func (s *Storage) Get(_ context.Context, index uint64) (*storage.QueuedTransaction, error) {
key := idxToKey(index)
value, err := s.db.Get(key)
if err != nil {
if errors.Is(err, leveldb.ErrNotFound) {
return nil, nil
}
return nil, err
}
return s.encDec().Decode(value)
}

func (s *Storage) lastItemIdx(context.Context) ([]byte, error) {
return s.db.Get(lastItemIdxKey)
}
Expand Down
4 changes: 4 additions & 0 deletions arbnode/dataposter/noop/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (s *Storage) FetchContents(_ context.Context, _, _ uint64) ([]*storage.Queu
return nil, nil
}

func (s *Storage) Get(_ context.Context, _ uint64) (*storage.QueuedTransaction, error) {
return nil, nil
}

func (s *Storage) FetchLast(ctx context.Context) (*storage.QueuedTransaction, error) {
return nil, nil
}
Expand Down
14 changes: 14 additions & 0 deletions arbnode/dataposter/redis/redisstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func (s *Storage) FetchContents(ctx context.Context, startingIndex uint64, maxRe
return items, nil
}

func (s *Storage) Get(ctx context.Context, index uint64) (*storage.QueuedTransaction, error) {
contents, err := s.FetchContents(ctx, index, 1)
if err != nil {
return nil, err
}
if len(contents) == 0 {
return nil, nil
} else if len(contents) == 1 {
return contents[0], nil
} else {
return nil, fmt.Errorf("expected only one return value for Get but got %v", len(contents))
}
}

func (s *Storage) FetchLast(ctx context.Context) (*storage.QueuedTransaction, error) {
query := redis.ZRangeArgs{
Key: s.key,
Expand Down
7 changes: 7 additions & 0 deletions arbnode/dataposter/slice/slicestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (s *Storage) FetchContents(_ context.Context, startingIndex uint64, maxResu
return res, nil
}

func (s *Storage) Get(_ context.Context, index uint64) (*storage.QueuedTransaction, error) {
if index >= s.firstNonce+uint64(len(s.queue)) || index < s.firstNonce {
return nil, nil
}
return s.encDec().Decode(s.queue[index-s.firstNonce])
}

func (s *Storage) FetchLast(context.Context) (*storage.QueuedTransaction, error) {
if len(s.queue) == 0 {
return nil, nil
Expand Down
44 changes: 26 additions & 18 deletions arbnode/dataposter/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,34 @@ var (
)

type QueuedTransaction struct {
FullTx *types.Transaction
DeprecatedData types.DynamicFeeTx // FullTx should be used instead
Meta []byte
Sent bool
Created time.Time // may be earlier than the tx was given to the tx poster
NextReplacement time.Time
FullTx *types.Transaction
DeprecatedData types.DynamicFeeTx // FullTx should be used instead
Meta []byte
Sent bool
Created time.Time // may be earlier than the tx was given to the tx poster
NextReplacement time.Time
CumulativeWeight uint64 // a rough estimate of the total number of batches submitted at this point, not guaranteed to be exact
}

type queuedTransactionForEncoding struct {
FullTx *types.Transaction
Data types.DynamicFeeTx
Meta []byte
Sent bool
Created RlpTime
NextReplacement RlpTime
FullTx *types.Transaction
Data types.DynamicFeeTx
Meta []byte
Sent bool
Created RlpTime
NextReplacement RlpTime
CumulativeWeight *uint64 `rlp:"optional"`
}

func (qt *QueuedTransaction) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, queuedTransactionForEncoding{
FullTx: qt.FullTx,
Data: qt.DeprecatedData,
Meta: qt.Meta,
Sent: qt.Sent,
Created: (RlpTime)(qt.Created),
NextReplacement: (RlpTime)(qt.NextReplacement),
FullTx: qt.FullTx,
Data: qt.DeprecatedData,
Meta: qt.Meta,
Sent: qt.Sent,
Created: (RlpTime)(qt.Created),
NextReplacement: (RlpTime)(qt.NextReplacement),
CumulativeWeight: &qt.CumulativeWeight,
})
}

Expand All @@ -65,6 +68,11 @@ func (qt *QueuedTransaction) DecodeRLP(s *rlp.Stream) error {
qt.Sent = qtEnc.Sent
qt.Created = time.Time(qtEnc.Created)
qt.NextReplacement = time.Time(qtEnc.NextReplacement)
if qtEnc.CumulativeWeight != nil {
qt.CumulativeWeight = *qtEnc.CumulativeWeight
} else {
qt.CumulativeWeight = qt.FullTx.Nonce()
}
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions util/arbmath/bips.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ func UintMulByBips(value uint64, bips Bips) uint64 {
func SaturatingCastToBips(value uint64) Bips {
return Bips(SaturatingCast(value))
}

// BigDivToBips returns dividend/divisor as bips, saturating if out of bounds
func BigDivToBips(dividend, divisor *big.Int) Bips {
value := BigMulByInt(dividend, int64(OneInBips))
value.Div(value, divisor)
return Bips(BigToUintSaturating(value))
}

0 comments on commit 20651e7

Please sign in to comment.