From 73c102235a3bd8ecd2504423f8c544e92a0b4257 Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Fri, 2 Aug 2024 10:09:59 +0400 Subject: [PATCH] use pointers to batch --- go.mod | 2 +- go.sum | 4 ++-- sequencing/sequencer.go | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 4866df2..c42f8c3 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gogo/protobuf v1.3.2 github.com/ipfs/go-log/v2 v2.5.1 github.com/rollkit/go-da v0.5.0 - github.com/rollkit/go-sequencing v0.0.0-20240719145307-0166b8267e96 + github.com/rollkit/go-sequencing v0.0.0-20240802060839-c195453f5eac github.com/rollkit/rollkit v0.13.6 ) diff --git a/go.sum b/go.sum index d672ede..d0daef3 100644 --- a/go.sum +++ b/go.sum @@ -316,8 +316,8 @@ github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDN github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rollkit/go-da v0.5.0 h1:sQpZricNS+2TLx3HMjNWhtRfqtvVC/U4pWHpfUz3eN4= github.com/rollkit/go-da v0.5.0/go.mod h1:VsUeAoPvKl4Y8wWguu/VibscYiFFePkkrvZWyTjZHww= -github.com/rollkit/go-sequencing v0.0.0-20240719145307-0166b8267e96 h1:5PDb1OkVhhe+FQdw6qX9agShN4bxH5Iz+bRrRmeMrZs= -github.com/rollkit/go-sequencing v0.0.0-20240719145307-0166b8267e96/go.mod h1:J6E6NR7tNJ0cKBxtVHnby0hQ+S7RTayuDfG1Llwv800= +github.com/rollkit/go-sequencing v0.0.0-20240802060839-c195453f5eac h1:tawGnkr4zMiGQDPlFOZupsw1HzGbbT9dHQNUcXyRmW4= +github.com/rollkit/go-sequencing v0.0.0-20240802060839-c195453f5eac/go.mod h1:J6E6NR7tNJ0cKBxtVHnby0hQ+S7RTayuDfG1Llwv800= github.com/rollkit/rollkit v0.13.6 h1:ZdIBG5D5RuQvnnJSY8s3m46dR3A3F6jHN+01zX+Avt0= github.com/rollkit/rollkit v0.13.6/go.mod h1:clM4aPsWDJk/IN/SqCBsA+ab0/8gdh+5O4hRkLWKB7s= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= diff --git a/sequencing/sequencer.go b/sequencing/sequencer.go index 6fbc5ec..748babb 100644 --- a/sequencing/sequencer.go +++ b/sequencing/sequencer.go @@ -289,19 +289,31 @@ func (c *Sequencer) SubmitRollupTransaction(ctx context.Context, rollupId []byte } // GetNextBatch implements sequencing.Sequencer. -func (c *Sequencer) GetNextBatch(ctx context.Context, lastBatch sequencing.Batch) (sequencing.Batch, error) { +func (c *Sequencer) GetNextBatch(ctx context.Context, lastBatch *sequencing.Batch) (*sequencing.Batch, error) { + // check the lastBatchHash to match the hash of the supplied lastBatch + if lastBatch == nil && c.lastBatchHash != nil { + return nil, errors.New("lastBatch is not supposed to be nil") + } + lastBatchBytes, err := lastBatch.Marshal() + if err != nil { + return nil, err + } + lastBatchHash := hashSHA256(lastBatchBytes) + if !bytes.Equal(c.lastBatchHash, lastBatchHash) { + return nil, errors.New("supplied lastBatch does not match with sequencer last batch") + } batch := c.bq.Next() batchBytes, err := batch.Marshal() if err != nil { - return sequencing.Batch{}, err + return nil, err } c.lastBatchHash = hashSHA256(batchBytes) c.seenBatches[string(c.lastBatchHash)] = struct{}{} - return *batch, nil + return batch, nil } // VerifyBatch implements sequencing.Sequencer. -func (c *Sequencer) VerifyBatch(ctx context.Context, batch sequencing.Batch) (bool, error) { +func (c *Sequencer) VerifyBatch(ctx context.Context, batch *sequencing.Batch) (bool, error) { //TODO: need to add DA verification batchBytes, err := batch.Marshal() if err != nil {