Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Jul 17, 2024
1 parent 83b2418 commit 43d8bcd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
5 changes: 5 additions & 0 deletions etherman/contracts/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package contracts

import (
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -63,6 +64,10 @@ type RollupData struct {
RollupCompatibilityID uint8
}

func (r *RollupData) String() string {
return fmt.Sprintf("RollupContract: %s, ChainID: %d, Verifier: %s, ForkID: %d, LastLocalExitRoot: %x, LastBatchSequenced: %d, LastVerifiedBatch: %d, LastPendingState: %d, LastPendingStateConsolidated: %d, LastVerifiedBatchBeforeUpgrade: %d, RollupTypeID: %d, RollupCompatibilityID: %d", r.RollupContract.String(), r.ChainID, r.Verifier.String(), r.ForkID, r.LastLocalExitRoot, r.LastBatchSequenced, r.LastVerifiedBatch, r.LastPendingState, r.LastPendingStateConsolidated, r.LastVerifiedBatchBeforeUpgrade, r.RollupTypeID, r.RollupCompatibilityID)
}

type StateVariablesSequencedBatchData struct {
AccInputHash [32]byte
SequencedTimestamp uint64
Expand Down
4 changes: 0 additions & 4 deletions sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,11 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) {
}

// Send sequences to L1
//sequenceCount := sequence.Len()
//firstSequence := sequence.Batches[0]
firstSequence := sequence.FirstBatch()
//lastSequence := sequence.Batches[sequenceCount-1]
lastSequence := sequence.LastBatch()
lastL2BlockTimestamp := lastSequence.LastL2BLockTimestamp()

log.Infof("[SeqSender] sending sequences to L1. From batch %d to batch %d", firstSequence.BatchNumber, lastSequence.BatchNumber)
//printSequenceBatches(sequence)
log.Infof(sequence.String())

// Wait until last L1 block timestamp is L1BlockTimestampMargin seconds above the timestamp of the last L2 block in the sequence
Expand Down
3 changes: 2 additions & 1 deletion sequencesender/sequencesender_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sequencesender

import (
"context"
"testing"

"github.com/0xPolygon/cdk/log"
Expand Down Expand Up @@ -66,7 +67,7 @@ func TestStreamTx(t *testing.T) {

func TestKK(t *testing.T) {
sut := &SequenceSender{}
sequences, err := sut.getSequencesToSend()
sequences, err := sut.getSequencesToSend(context.TODO())
require.NoError(t, err)
require.NotNil(t, sequences)
}
21 changes: 18 additions & 3 deletions sequencesender/txbuilder/banana_base.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package txbuilder

import (
"fmt"

cdkcommon "github.com/0xPolygon/cdk/common"
"github.com/0xPolygon/cdk/etherman"
"github.com/0xPolygon/cdk/etherman/contracts"
"github.com/0xPolygon/cdk/log"
"github.com/0xPolygon/cdk/sequencesender/seqsendertypes"
"github.com/0xPolygon/cdk/state/datastream"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -17,9 +20,21 @@ type TxBuilderBananaBase struct {
SenderAddress common.Address
}

func convertToSequenceBanana(sequences seqsendertypes.Sequence) etherman.SequenceBanana {
// TODO: Fill
return etherman.SequenceBanana{}
func convertToSequenceBanana(sequences seqsendertypes.Sequence) (etherman.SequenceBanana, error) {
seqEth, ok := sequences.(*BananaSequence)
if !ok {
log.Error("sequences is not a BananaSequence")
return etherman.SequenceBanana{}, fmt.Errorf("sequences is not a BananaSequence")
}
seqEth.SequenceBanana.Batches = make([]etherman.Batch, len(sequences.Batches()))
for _, batch := range sequences.Batches() {
ethBatch, err := convertToEthermanBatch(batch)
if err != nil {
return etherman.SequenceBanana{}, err
}
seqEth.SequenceBanana.Batches = append(seqEth.SequenceBanana.Batches, ethBatch)
}
return seqEth.SequenceBanana, nil
}

func convertToEthermanBatch(batch seqsendertypes.Batch) (etherman.Batch, error) {
Expand Down
6 changes: 5 additions & 1 deletion sequencesender/txbuilder/banana_validium.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func (t *TxBuilderBananaValidium) BuildSequenceBatchesTx(ctx context.Context, se
// Post sequences to DA backend
var dataAvailabilityMessage []byte
var err error
ethseq := convertToSequenceBanana(sequences)
ethseq, err := convertToSequenceBanana(sequences)
if err != nil {
log.Error("error converting sequences to etherman: ", err)
return nil, err
}

dataAvailabilityMessage, err = t.da.PostSequence(ctx, ethseq)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion sequencesender/txbuilder/banana_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ func (t *TxBuilderBananaZKEVM) NewSequenceIfWorthToSend(ctx context.Context, seq

func (t *TxBuilderBananaZKEVM) BuildSequenceBatchesTx(ctx context.Context, sender common.Address, sequences seqsendertypes.Sequence) (*ethtypes.Transaction, error) {
var err error
ethseq := convertToSequenceBanana(sequences)
ethseq, err := convertToSequenceBanana(sequences)
if err != nil {
log.Error("error converting sequences to etherman: ", err)
return nil, err
}
newopts := t.opts
newopts.NoSend = true

Expand Down

0 comments on commit 43d8bcd

Please sign in to comment.