Skip to content

Commit

Permalink
Support batch data location for batch hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Jan 24, 2024
1 parent 2bd34c6 commit ac0978f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions arbnode/sequencer_inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/offchainlabs/nitro/arbstate"
"github.com/offchainlabs/nitro/arbutil"

"github.com/offchainlabs/nitro/solgen/go/bridgegen"
Expand All @@ -33,6 +34,7 @@ const (
batchDataTxInput batchDataLocation = iota
batchDataSeparateEvent
batchDataNone
batchDataBlobHashes
)

func init() {
Expand Down Expand Up @@ -149,6 +151,19 @@ func (m *SequencerInboxBatch) getSequencerData(ctx context.Context, client arbut
case batchDataNone:
// No data when in a force inclusion batch
return nil, nil
case batchDataBlobHashes:
tx, err := arbutil.GetLogTransaction(ctx, client, m.rawLog)
if err != nil {
return nil, err
}
if len(tx.BlobHashes()) == 0 {
return nil, fmt.Errorf("blob batch transaction %v has no blobs", tx.Hash())
}
data := []byte{arbstate.BlobHashesHeaderFlag}
for _, h := range tx.BlobHashes() {
data = append(data, h[:]...)
}
return data, nil
default:
return nil, fmt.Errorf("batch has invalid data location %v", m.dataLocation)
}
Expand Down
12 changes: 10 additions & 2 deletions arbutil/transaction_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)

// GetLogEmitterTxData requires that the tx's data is at least 4 bytes long
func GetLogEmitterTxData(ctx context.Context, client L1Interface, log types.Log) ([]byte, error) {
func GetLogTransaction(ctx context.Context, client L1Interface, log types.Log) (*types.Transaction, error) {
tx, err := client.TransactionInBlock(ctx, log.BlockHash, log.TxIndex)
if err != nil {
return nil, err
}
if tx.Hash() != log.TxHash {
return nil, fmt.Errorf("L1 client returned unexpected transaction hash %v when looking up block %v transaction %v with expected hash %v", tx.Hash(), log.BlockHash, log.TxIndex, log.TxHash)
}
return tx, nil
}

// GetLogEmitterTxData requires that the tx's data is at least 4 bytes long
func GetLogEmitterTxData(ctx context.Context, client L1Interface, log types.Log) ([]byte, error) {
tx, err := GetLogTransaction(ctx, client, log)
if err != nil {
return nil, err
}
if len(tx.Data()) < 4 {
return nil, fmt.Errorf("log emitting transaction %v unexpectedly does not have enough data", tx.Hash())
}
Expand Down

0 comments on commit ac0978f

Please sign in to comment.