Skip to content

Commit

Permalink
Extract L1 API call to method: GetBlobSidecarsByRefAndIndexedDataHash…
Browse files Browse the repository at this point in the history
…es (#9)

* Extract L1 API call to method: GetBlobSidecarsByRefAndIndexedDataHashes

* Fix function declaration & add godoc comments
  • Loading branch information
KNWR authored and roberto-bayardo committed Dec 23, 2023
1 parent 2ee78f4 commit 536034a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 16 additions & 4 deletions op-service/sources/l1_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (cl *L1BeaconClient) apiReq(ctx context.Context, dest any, method string) e
return nil
}

// GetTimeToSlotFn returns a function that converts a timestamp to a slot number.
func (cl *L1BeaconClient) GetTimeToSlotFn(ctx context.Context) (TimeToSlotFn, error) {
cl.initLock.Lock()
defer cl.initLock.Unlock()
Expand All @@ -74,9 +75,9 @@ func (cl *L1BeaconClient) GetTimeToSlotFn(ctx context.Context) (TimeToSlotFn, er
return cl.timeToSlotFn, nil
}

// BlobsByRefAndIndexedDataHashes fetches blobs that were confirmed in the given L1 block with the
// given indexed hashes. The order of the returned blobs will match the order of `dataHashes`.
func (cl *L1BeaconClient) BlobsByRefAndIndexedDataHashes(ctx context.Context, ref eth.L1BlockRef, dataHashes []eth.IndexedDataHash) ([]*eth.Blob, error) {
// GetBlobSidecarsByRefAndIndexedDataHashes fetches blob sidecars that were confirmed in the given L1 block with the
// given indexed hashes.
func (cl *L1BeaconClient) GetBlobSidecarsByRefAndIndexedDataHashes(ctx context.Context, ref eth.L1BlockRef, dataHashes []eth.IndexedDataHash) ([]*eth.BlobSidecar, error) {
slotFn, err := cl.GetTimeToSlotFn(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get time to slot function: %w", err)
Expand All @@ -103,13 +104,24 @@ func (cl *L1BeaconClient) BlobsByRefAndIndexedDataHashes(ctx context.Context, re
return nil, fmt.Errorf("expected %v sidecars but got %v", len(dataHashes), len(resp.Data))
}

return resp.Data, nil
}

// BlobsByRefAndIndexedDataHashes fetches blobs that were confirmed in the given L1 block with the
// given indexed hashes. The order of the returned blobs will match the order of `dataHashes`.
func (cl *L1BeaconClient) BlobsByRefAndIndexedDataHashes(ctx context.Context, ref eth.L1BlockRef, dataHashes []eth.IndexedDataHash) ([]*eth.Blob, error) {
blobSidecars, err := cl.GetBlobSidecarsByRefAndIndexedDataHashes(ctx, ref, dataHashes)
if err != nil {
return nil, err
}

out := make([]*eth.Blob, len(dataHashes))
for i, ih := range dataHashes {
// The beacon node api makes no guarantees on order of the returned blob sidecars, so
// search for the sidecar that matches the current indexed hash to ensure blobs are
// returned in the same order.
var sidecar *eth.BlobSidecar
for _, sc := range resp.Data {
for _, sc := range blobSidecars {
if uint64(sc.Index) == ih.Index {
sidecar = sc
break
Expand Down
3 changes: 2 additions & 1 deletion op-service/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
blobPriceBumpPercent = big.NewInt(100 + blobPriceBump)

oneHundred = big.NewInt(100)
ninetyNine = big.NewInt(99)
two = big.NewInt(2)
)

Expand Down Expand Up @@ -706,7 +707,7 @@ func (m *SimpleTxManager) checkLimits(tip, basefee, bumpedTip, bumpedFee *big.In

// calcThresholdValue returns ceil(x * priceBumpPercent / 100)
// It guarantees that x is increased by at least 1
func calcThresholdValue(x *big.Int) *big.Int {
func calcThresholdValue(x *big.Int, isBlobTx bool) *big.Int {
var percent *big.Int
if isBlobTx {
percent = blobPriceBumpPercent
Expand Down

0 comments on commit 536034a

Please sign in to comment.