Skip to content

Commit

Permalink
use pointers to batch
Browse files Browse the repository at this point in the history
  • Loading branch information
gupadhyaya committed Aug 2, 2024
1 parent 38f6528 commit 73c1022
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
20 changes: 16 additions & 4 deletions sequencing/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 73c1022

Please sign in to comment.