Skip to content

Commit

Permalink
fix: happy golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Aug 12, 2024
1 parent 279c119 commit eaddb0e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 36 deletions.
18 changes: 9 additions & 9 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ type BatchPoster struct {
dapWriter daprovider.Writer
// This deviates from the DA spec but is necessary for the batch poster to work efficiently
// since we need to an extended method on the SequencerInbox contract
eigenDAWriter eigenda.EigenDAWriter
dataPoster *dataposter.DataPoster
redisLock *redislock.Simple
messagesPerBatch *arbmath.MovingAverage[uint64]
non4844BatchCount int // Count of consecutive non-4844 batches posted
eigenDAWriter eigenda.EigenDAWriter
dataPoster *dataposter.DataPoster
redisLock *redislock.Simple
messagesPerBatch *arbmath.MovingAverage[uint64]
non4844BatchCount int // Count of consecutive non-4844 batches posted
// This is an atomic variable that should only be accessed atomically.
// An estimate of the number of batches we want to post but haven't yet.
// This doesn't include batches which we don't want to post yet due to the L1 bounds.
Expand Down Expand Up @@ -238,7 +238,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
Enable: false,
DisableDapFallbackStoreDataOnChain: false,
// This default is overridden for L3 chains in applyChainParameters in cmd/nitro/nitro.go
MaxSize: 100000,
MaxSize: 100000,
MaxEigenDABatchSize: 2_000_000,
// Try to fill 3 blobs per batch
Max4844BatchSize: blobs.BlobEncodableData*(params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)/2 - 2000,
Expand Down Expand Up @@ -274,7 +274,7 @@ var TestBatchPosterConfig = BatchPosterConfig{
Enable: true,
MaxSize: 100000,
Max4844BatchSize: DefaultBatchPosterConfig.Max4844BatchSize,
MaxEigenDABatchSize: DefaultBatchPosterConfig.MaxEigenDABatchSize,
MaxEigenDABatchSize: DefaultBatchPosterConfig.MaxEigenDABatchSize,
PollInterval: time.Millisecond * 10,
ErrorDelay: time.Millisecond * 10,
MaxDelay: 0,
Expand All @@ -298,7 +298,7 @@ var EigenDABatchPosterConfig = BatchPosterConfig{
Enable: true,
MaxSize: 100000,
Max4844BatchSize: DefaultBatchPosterConfig.Max4844BatchSize,
MaxEigenDABatchSize: DefaultBatchPosterConfig.MaxEigenDABatchSize,
MaxEigenDABatchSize: DefaultBatchPosterConfig.MaxEigenDABatchSize,
PollInterval: time.Millisecond * 10,
ErrorDelay: time.Millisecond * 10,
MaxDelay: 0,
Expand Down Expand Up @@ -710,7 +710,7 @@ type buildingBatch struct {
msgCount arbutil.MessageIndex
haveUsefulMessage bool
use4844 bool
useEigenDA bool
useEigenDA bool
}

func newBatchSegments(firstDelayed uint64, config *BatchPosterConfig, backlog uint64, use4844 bool, useEigenDA bool) *batchSegments {
Expand Down
4 changes: 2 additions & 2 deletions arbnode/sequencer_inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func (m *SequencerInboxBatch) getSequencerData(ctx context.Context, client arbut

calldata := tx.Data()
data := []byte{daprovider.EigenDAMessageHeaderFlag}
data = append(data, calldata[:]...)
data = append(data, calldata...)

return data, nil
default:
return nil, fmt.Errorf("batch has invalid data location %v", m.dataLocation)
Expand Down
4 changes: 2 additions & 2 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ func mainImpl() int {

// NOTE: since the SRS is stored within the arbitrator and predetermines the max batch size
// supported for proving stateless execution - it could be possible to read from dynamically
// otherwise it maybe best to expose the max supported batch size from the disperser directly
// to ensure dynamically adaptability within the rollup.
// otherwise it maybe best to expose the max supported batch size from the disperser directly
// to ensure dynamically adaptability within the rollup.
if nodeConfig.Node.BatchPoster.Enable && nodeConfig.Node.EigenDA.Enable {
if nodeConfig.Node.BatchPoster.MaxEigenDABatchSize > eigenda.MaxBatchSize {
log.Error("batchPoster's MaxEigenDABatchSize too large.", "MaxEigenDABatchSize", eigenda.MaxBatchSize)
Expand Down
7 changes: 3 additions & 4 deletions cmd/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (dasReader *PreimageDASReader) ExpirationPolicy(ctx context.Context) (dapro
}

type BlobPreimageReader struct{}

func (r *BlobPreimageReader) GetBlobs(
ctx context.Context,
batchBlockHash common.Hash,
Expand All @@ -149,8 +150,8 @@ func (r *BlobPreimageReader) Initialize(ctx context.Context) error {
return nil
}


type EigenDAPreimageReader struct{}

// QueryBlob returns the blob for the given cert from the preimage oracle using the hash of the
// certificate kzg commitment for identifying the preimage.
func (dasReader *EigenDAPreimageReader) QueryBlob(ctx context.Context, cert *eigenda.EigenDABlobInfo, domain string) ([]byte, error) {
Expand All @@ -177,12 +178,10 @@ func (dasReader *EigenDAPreimageReader) QueryBlob(ctx context.Context, cert *eig
println("Error decoding blob: ", err)
return nil, err
}

return decodedBlob, nil
}



// To generate:
// key, _ := crypto.HexToECDSA("0000000000000000000000000000000000000000000000000000000000000001")
// sig, _ := crypto.Sign(make([]byte, 32), key)
Expand Down
11 changes: 4 additions & 7 deletions eigenda/decoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func DecodeBlob(data []byte) ([]byte, error) {

}


func EncodeBlob(data []byte) ([]byte, error) {
var err error
data, err = encodeBlob(data)
Expand All @@ -104,8 +103,6 @@ func EncodeBlob(data []byte) ([]byte, error) {
return IFFT(data)
}



func encodeBlob(rawData []byte) ([]byte, error) {
codecBlobHeader := make([]byte, 32)
// first byte is always 0 to ensure the codecBlobHeader is a valid bn254 element
Expand All @@ -118,13 +115,13 @@ func encodeBlob(rawData []byte) ([]byte, error) {
// encode raw data modulo bn254
rawDataPadded := codec.ConvertByPaddingEmptyByte(rawData)

// append raw data
encodedData := append(codecBlobHeader, rawDataPadded...)
// append raw data; reassgin avoids copying
encodedData := codecBlobHeader
encodedData = append(encodedData, rawDataPadded...)

return encodedData, nil
}


func IFFT(data []byte) ([]byte, error) {
// we now IFFT data regardless of the encoding type
// convert data to fr.Element
Expand Down Expand Up @@ -156,4 +153,4 @@ func IFFT(data []byte) ([]byte, error) {
}

return rs.ToByteArray(dataIFFTFr, dataFrLenPow2*encoding.BYTES_PER_SYMBOL), nil
}
}
9 changes: 4 additions & 5 deletions eigenda/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ type EigenDAProxyClient struct {
client ProxyClient
}

func NewEigenDAProxyClient(RPCUrl string) *EigenDAProxyClient {

func NewEigenDAProxyClient(rpcUrl string) *EigenDAProxyClient {
c := New(&Config{
URL: RPCUrl,
URL: rpcUrl,
})
return &EigenDAProxyClient{client: c}
}
Expand Down Expand Up @@ -89,7 +88,7 @@ func StrToDomainType(s string) DomainType {

// TODO: Add support for custom http client option
type Config struct {
URL string
URL string
}

// ProxyClient is an interface for communicating with the EigenDA proxy server
Expand Down Expand Up @@ -141,7 +140,7 @@ func (c *client) GetData(ctx context.Context, comm []byte, domain DomainType) ([

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, fmt.Errorf("failed to construct http request: %e", err)
return nil, fmt.Errorf("failed to construct http request: %w", err)
}

req.Header.Set("Content-Type", "application/octet-stream")
Expand Down
7 changes: 3 additions & 4 deletions eigenda/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ func (d *readerForEigenDA) RecoverPayloadFromBatch(
preimageRecorder daprovider.PreimageRecorder,
validateSeqMsg bool,
) ([]byte, error) {
// offset sequencer message at 41
// offset sequencer message at 41
return RecoverPayloadFromEigenDABatch(ctx, sequencerMsg[41:], d.readerEigenDA, preimageRecorder, "binary")
}


func RecoverPayloadFromEigenDABatch(ctx context.Context,
sequencerMsg []byte,
daReader EigenDAReader,
Expand Down Expand Up @@ -83,7 +82,7 @@ func RecoverPayloadFromEigenDABatch(ctx context.Context,

// ParseSequencerMsg parses the inbox tx calldata into a structured EigenDABlobInfo
func ParseSequencerMsg(calldata []byte) (*EigenDABlobInfo, error) {

if len(calldata) < 4 {
return nil, errors.New("calldata is shorter than expected method signature length")
}
Expand Down Expand Up @@ -140,6 +139,6 @@ func (d *binaryReaderForEigenDA) RecoverPayloadFromBatch(
preimageRecorder daprovider.PreimageRecorder,
validateSeqMsg bool,
) ([]byte, error) {
// offset sequencer message at 41
// offset sequencer message at 41
return RecoverPayloadFromEigenDABatch(ctx, sequencerMsg[41:], d.readerEigenDA, preimageRecorder, "binary")
}
30 changes: 28 additions & 2 deletions eigenda/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ func (e *EigenDABlobInfo) ToDisperserBlobInfo() (*DisperserBlobInfo, error) {

// Convert BlobVerificationProof
var disperserBlobVerificationProof DisperserBlobVerificationProof
if &e.BlobVerificationProof != nil {
if !e.BlobVerificationProof.IsEmpty() {
var disperserBatchMetadata DisperserBatchMetadata
if &e.BlobVerificationProof.BatchMetadata != nil {
if !e.BlobVerificationProof.BatchMetadata.IsEmpty() {
metadata := e.BlobVerificationProof.BatchMetadata
quorumNumbers := metadata.BatchHeader.QuorumNumbers
quorumSignedPercentages := metadata.BatchHeader.SignedStakeForQuorums
Expand Down Expand Up @@ -395,3 +395,29 @@ func (ip *InboxPayload) Load(callDataValues []interface{}) error {
*ip = payload
return nil
}

// IsEmpty checks if BlobVerificationProof is effectively empty
func (b BlobVerificationProof) IsEmpty() bool {
return b.BatchID == 0 &&
b.BlobIndex == 0 &&
b.BatchMetadata.IsEmpty() &&
len(b.InclusionProof) == 0 &&
len(b.QuorumIndices) == 0
}

// IsEmpty checks if BatchMetadata is effectively empty
func (bm BatchMetadata) IsEmpty() bool {
return bm.BatchHeader.IsEmpty() &&
len(bm.Fee) == 0 &&
bm.SignatoryRecordHash == [32]byte{} &&
bm.ConfirmationBlockNumber == 0 &&
len(bm.BatchHeaderHash) == 0
}

// IsEmpty checks if BatchHeader is effectively empty
func (bh BatchHeader) IsEmpty() bool {
return bh.BlobHeadersRoot == [32]byte{} &&
len(bh.QuorumNumbers) == 0 &&
len(bh.SignedStakeForQuorums) == 0 &&
bh.ReferenceBlockNumber == 0
}
1 change: 0 additions & 1 deletion validator/server_jit/jit_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (machine *JitMachine) close() {
func (machine *JitMachine) prove(
ctxIn context.Context, entry *validator.ValidationInput,
) (validator.GoGlobalState, error) {


ctx, cancel := context.WithCancel(ctxIn)
defer cancel() // ensure our cleanup functions run when we're done
Expand Down

0 comments on commit eaddb0e

Please sign in to comment.