-
Notifications
You must be signed in to change notification settings - Fork 3
Conform to nitro's DataAvailabilityProvider interface #1
base: eigenda
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -64,8 +64,9 @@ var ( | |||||
const ( | ||||||
batchPosterSimpleRedisLockKey = "node.batch-poster.redis-lock.simple-lock-key" | ||||||
|
||||||
sequencerBatchPostMethodName = "addSequencerL2BatchFromOrigin0" | ||||||
sequencerBatchPostWithBlobsMethodName = "addSequencerL2BatchFromBlobs" | ||||||
sequencerBatchPostMethodName = "addSequencerL2BatchFromOrigin0" | ||||||
sequencerBatchPostWithBlobsMethodName = "addSequencerL2BatchFromBlobs" | ||||||
sequencerBatchPostWithEigendaMethodName = "addSequencerL2BatchFromEigenDA" | ||||||
) | ||||||
|
||||||
type batchPosterPosition struct { | ||||||
|
@@ -847,19 +848,38 @@ func (b *BatchPoster) encodeAddBatch( | |||||
l2MessageData []byte, | ||||||
delayedMsg uint64, | ||||||
use4844 bool, | ||||||
useEigenDA bool, | ||||||
eigenDaBlobInfo *eigenda.EigenDABlobInfo, | ||||||
) ([]byte, []kzg4844.Blob, error) { | ||||||
methodName := sequencerBatchPostMethodName | ||||||
if use4844 { | ||||||
methodName = sequencerBatchPostWithBlobsMethodName | ||||||
} | ||||||
|
||||||
if useEigenDA { | ||||||
methodName = sequencerBatchPostWithEigendaMethodName | ||||||
} | ||||||
|
||||||
method, ok := b.seqInboxABI.Methods[methodName] | ||||||
if !ok { | ||||||
return nil, nil, errors.New("failed to find add batch method") | ||||||
} | ||||||
var calldata []byte | ||||||
var kzgBlobs []kzg4844.Blob | ||||||
var err error | ||||||
if use4844 { | ||||||
|
||||||
if useEigenDA { | ||||||
calldata, err = method.Inputs.Pack( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should prolly be checking this error |
||||||
seqNum, | ||||||
eigenDaBlobInfo.BlobVerificationProof, | ||||||
eigenDaBlobInfo.BlobHeader, | ||||||
new(big.Int).SetUint64(delayedMsg), | ||||||
b.config().gasRefunder, | ||||||
new(big.Int).SetUint64(uint64(prevMsgNum)), | ||||||
new(big.Int).SetUint64(uint64(newMsgNum)), | ||||||
) | ||||||
kzgBlobs, err = blobs.EncodeBlobs(l2MessageData) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where do we override this? If not mistaken this is using the same encoding for 4844 blobs |
||||||
} else if use4844 { | ||||||
kzgBlobs, err = blobs.EncodeBlobs(l2MessageData) | ||||||
if err != nil { | ||||||
return nil, nil, fmt.Errorf("failed to encode blobs: %w", err) | ||||||
|
@@ -907,7 +927,7 @@ func estimateGas(client rpc.ClientInterface, ctx context.Context, params estimat | |||||
return uint64(gas), err | ||||||
} | ||||||
|
||||||
func (b *BatchPoster) estimateGas(ctx context.Context, sequencerMessage []byte, delayedMessages uint64, realData []byte, realBlobs []kzg4844.Blob, realNonce uint64, realAccessList types.AccessList) (uint64, error) { | ||||||
func (b *BatchPoster) estimateGas(ctx context.Context, sequencerMessage []byte, delayedMessages uint64, realData []byte, realBlobs []kzg4844.Blob, realNonce uint64, realAccessList types.AccessList, eigenDaBlobInfo *eigenda.EigenDABlobInfo) (uint64, error) { | ||||||
config := b.config() | ||||||
rpcClient := b.l1Reader.Client() | ||||||
rawRpcClient := rpcClient.Client() | ||||||
|
@@ -949,7 +969,7 @@ func (b *BatchPoster) estimateGas(ctx context.Context, sequencerMessage []byte, | |||||
// However, we set nextMsgNum to 1 because it is necessary for a correct estimation for the final to be non-zero. | ||||||
// Because we're likely estimating against older state, this might not be the actual next message, | ||||||
// but the gas used should be the same. | ||||||
data, kzgBlobs, err := b.encodeAddBatch(abi.MaxUint256, 0, 1, sequencerMessage, delayedMessages, len(realBlobs) > 0) | ||||||
data, kzgBlobs, err := b.encodeAddBatch(abi.MaxUint256, 0, 1, sequencerMessage, delayedMessages, len(realBlobs) > 0, true, eigenDaBlobInfo) | ||||||
if err != nil { | ||||||
return 0, err | ||||||
} | ||||||
|
@@ -1224,26 +1244,29 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error) | |||||
} | ||||||
} | ||||||
|
||||||
var blobInfo *eigenda.EigenDABlobInfo | ||||||
var blobID *eigenda.EigenDABlobID | ||||||
|
||||||
if b.daWriter == nil && b.eigenDAWriter != nil { | ||||||
log.Info("Start to write data to eigenda: ", "data", hex.EncodeToString(sequencerMsg)) | ||||||
daRef, err := b.eigenDAWriter.Store(ctx, sequencerMsg) | ||||||
blobID, blobInfo, err = b.eigenDAWriter.Store(ctx, sequencerMsg) | ||||||
if err != nil { | ||||||
if config.DisableEigenDAFallbackStoreDataOnChain { | ||||||
log.Warn("Falling back to storing data on chain", "err", err) | ||||||
return false, errors.New("unable to post batch to EigenDA and fallback storing data on chain is disabled") | ||||||
} | ||||||
} | ||||||
|
||||||
pointer, err := b.eigenDAWriter.Serialize(daRef) | ||||||
pointer, err := b.eigenDAWriter.Serialize(blobID) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not?
Suggested change
|
||||||
if err != nil { | ||||||
log.Warn("DaRef serialization failed", "err", err) | ||||||
return false, errors.New("DaRef serialization failed") | ||||||
} | ||||||
log.Info("EigenDA transaction receipt(data pointer): ", "hash", hex.EncodeToString(daRef.BatchHeaderHash), "index", daRef.BlobIndex) | ||||||
log.Info("EigenDA transaction receipt(data pointer): ", "hash", hex.EncodeToString(blobID.BatchHeaderHash), "index", blobID.BlobIndex) | ||||||
sequencerMsg = pointer | ||||||
} | ||||||
|
||||||
data, kzgBlobs, err := b.encodeAddBatch(new(big.Int).SetUint64(batchPosition.NextSeqNum), batchPosition.MessageCount, b.building.msgCount, sequencerMsg, b.building.segments.delayedMsg, b.building.use4844) | ||||||
data, kzgBlobs, err := b.encodeAddBatch(new(big.Int).SetUint64(batchPosition.NextSeqNum), batchPosition.MessageCount, b.building.msgCount, sequencerMsg, b.building.segments.delayedMsg, b.building.use4844, true, blobInfo) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we be binding this boolean as a config value to the |
||||||
if err != nil { | ||||||
return false, err | ||||||
} | ||||||
|
@@ -1258,7 +1281,7 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error) | |||||
// In theory, this might reduce gas usage, but only by a factor that's already | ||||||
// accounted for in `config.ExtraBatchGas`, as that same factor can appear if a user | ||||||
// posts a new delayed message that we didn't see while gas estimating. | ||||||
gasLimit, err := b.estimateGas(ctx, sequencerMsg, lastPotentialMsg.DelayedMessagesRead, data, kzgBlobs, nonce, accessList) | ||||||
gasLimit, err := b.estimateGas(ctx, sequencerMsg, lastPotentialMsg.DelayedMessagesRead, data, kzgBlobs, nonce, accessList, blobInfo) | ||||||
if err != nil { | ||||||
return false, err | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |||||
"github.com/ethereum/go-ethereum/core/types" | ||||||
"github.com/offchainlabs/nitro/arbstate" | ||||||
"github.com/offchainlabs/nitro/arbutil" | ||||||
"github.com/offchainlabs/nitro/das/eigenda" | ||||||
|
||||||
"github.com/offchainlabs/nitro/solgen/go/bridgegen" | ||||||
) | ||||||
|
@@ -35,6 +36,7 @@ const ( | |||||
batchDataSeparateEvent | ||||||
batchDataNone | ||||||
batchDataBlobHashes | ||||||
batchDataEigenDA | ||||||
) | ||||||
|
||||||
func init() { | ||||||
|
@@ -164,6 +166,24 @@ func (m *SequencerInboxBatch) getSequencerData(ctx context.Context, client arbut | |||||
data = append(data, h[:]...) | ||||||
} | ||||||
return data, nil | ||||||
case batchDataEigenDA: | ||||||
// get the transaction data from the log | ||||||
tx, err := arbutil.GetLogTransaction(ctx, client, m.rawLog) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
// get the input data from the transaction | ||||||
// TODO: decide on if you want to parse it here or parse it upstream, I've decided to parse it upstream and include all of the calldata in the batch | ||||||
calldata := tx.Data() | ||||||
|
||||||
// append the eigenDA header flag to the front | ||||||
data := []byte{eigenda.EigenDAMessageHeaderFlag} | ||||||
data = append(data, calldata[:]...) | ||||||
|
||||||
// format of eigenDA data is | ||||||
// [0 - 1] header flag | ||||||
// [1 - len(data)] calldata | ||||||
return data, nil | ||||||
default: | ||||||
return nil, fmt.Errorf("batch has invalid data location %v", m.dataLocation) | ||||||
} | ||||||
|
@@ -199,6 +219,11 @@ func (m *SequencerInboxBatch) Serialize(ctx context.Context, client arbutil.L1In | |||||
|
||||||
m.serialized = fullData | ||||||
return fullData, nil | ||||||
|
||||||
// in the case of eigenDA the serialized data looks like this | ||||||
// [0-40] Header Vals | ||||||
// [40-41]eigenDA header flag | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||
// [41 - len(fullData)] transaction calldata | ||||||
} | ||||||
|
||||||
func (i *SequencerInbox) LookupBatchesInRange(ctx context.Context, from, to *big.Int) ([]*SequencerInboxBatch, error) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: feel like an enum (e.g,
DataSource
) would be the best representation for this