Skip to content

Commit

Permalink
Initialised pipeline for coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
Shailu-s committed Nov 12, 2024
1 parent 549d31f commit b1ad403
Show file tree
Hide file tree
Showing 8 changed files with 792 additions and 19 deletions.
18 changes: 18 additions & 0 deletions sequencer/batchbuilder/batchbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,21 @@ func (bb *BatchBuilder) Reset(batchNum common.BatchNum, fromSynchronizer bool) e
//TODO: Check and Update this reseting functionality
// return tracerr.Wrap(bb.localStateDB.Reset(batchNum, fromSynchronizer))
}

// BuildBatch takes the transactions and returns the common.ZKInputs of the next batch
func (bb *BatchBuilder) BuildBatch(configBatch *ConfigBatch, l1usertxs []common.L1Tx, pooll2txs []common.PoolL2Tx) (*common.ZKInputs, error) {
bbStateDB := bb.localStateDB.StateDB
tp := txprocessor.NewTxProcessor(bbStateDB, configBatch.TxProcessorConfig)

//TODO: Need to update this once PR which has updates regarding tx processor is merged
ptOut, err := tp.ProcessTxs(nil, l1usertxs, nil, pooll2txs)
if err != nil {
return nil, common.Wrap(err)
}
return ptOut.ZKInputs, nil
}

// LocalStateDB returns the underlying LocalStateDB
func (bb *BatchBuilder) LocalStateDB() *statedb.LocalStateDB {
return bb.localStateDB
}
6 changes: 6 additions & 0 deletions sequencer/common/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ func AccountFromBytes(b [32 * NAccountLeafElems]byte) (*Account, error) {
return &a, nil
}

// IdxNonce is a pair of Idx and Nonce representing an account
type IdxAccountNonce struct {
Idx AccountIdx `db:"idx"`
Nonce Nonce `db:"nonce"`
}

// AccountUpdate represents an account balance and/or nonce update after a
// processed batch
type AccountUpdate struct {
Expand Down
5 changes: 5 additions & 0 deletions sequencer/common/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (bn BatchNum) Bytes() []byte {
return batchNumBytes[:]
}

// BigInt returns a *big.Int representing the BatchNum
func (bn BatchNum) BigInt() *big.Int {
return big.NewInt(int64(bn))
}

// BatchNumFromBytes returns BatchNum from a []byte
func BatchNumFromBytes(b []byte) (BatchNum, error) {
if len(b) != batchNumBytesLen {
Expand Down
25 changes: 25 additions & 0 deletions sequencer/common/pooll2tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ type PoolL2Tx struct {
// PoolL2TxState is a string that represents the status of a L2 transaction
type PoolL2TxState string

// TxSelectorError struct that gives more details about the error
type TxSelectorError struct {
Message string `meddler:"info,zeroisnull"`
Code int `meddler:"error_code,zeroisnull"`
Type string `meddler:"error_type,zeroisnull"`
}

const (
// PoolL2TxStatePending represents a valid L2Tx that hasn't started the
// forging process
Expand Down Expand Up @@ -347,3 +354,21 @@ func (tx *PoolL2Tx) HashToSign(chainID uint16) (*big.Int, error) {
return poseidon.Hash([]*big.Int{toCompressedData, e1, toBJJY, rqTxCompressedDataV2,
rqToEthAddr, rqToBJJY})
}

// TxIDsFromPoolL2Txs returns an array of TxID from the []PoolL2Tx
func TxIDsFromPoolL2Txs(txs []PoolL2Tx) []TxID {
txIDs := make([]TxID, len(txs))
for i, tx := range txs {
txIDs[i] = tx.TxID
}
return txIDs
}

// PoolL2TxsToL2Txs returns an array of []L2Tx from an array of []PoolL2Tx
func PoolL2TxsToL2Txs(txs []PoolL2Tx) ([]L2Tx, error) {
l2Txs := make([]L2Tx, len(txs))
for i, poolTx := range txs {
l2Txs[i] = poolTx.L2Tx()
}
return l2Txs, nil
}
55 changes: 37 additions & 18 deletions sequencer/coordinator/batch.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package coordinator

import (
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"path"
"time"
"tokamak-sybil-resistance/common"
"tokamak-sybil-resistance/coordinator/prover"
Expand Down Expand Up @@ -72,24 +76,21 @@ type Debug struct {

// BatchInfo contans the Batch information
type BatchInfo struct {
PipelineNum int
BatchNum common.BatchNum
ServerProof prover.Client
ProofStart time.Time
ZKInputs *common.ZKInputs
Proof *prover.Proof
PublicInputs []*big.Int
L1Batch bool
VerifierIdx uint8
L1UserTxs []common.L1Tx
L1CoordTxs []common.L1Tx
L1CoordinatorTxsAuths [][]byte
L2Txs []common.L2Tx
CoordIdxs []common.AccountIdx
ForgeBatchArgs *eth.RollupForgeBatchArgs
Auth *bind.TransactOpts `json:"-"`
EthTxs []*types.Transaction
EthTxsErrs []error
PipelineNum int
BatchNum common.BatchNum
ServerProof prover.Client
ProofStart time.Time
ZKInputs *common.ZKInputs
Proof *prover.Proof
PublicInputs []*big.Int
L1Batch bool
L1UserTxs []common.L1Tx
L2Txs []common.L2Tx
VerifierIdx uint8
ForgeBatchArgs *eth.RollupForgeBatchArgs
Auth *bind.TransactOpts `json:"-"`
EthTxs []*types.Transaction
EthTxsErrs []error
// SendTimestamp the time of batch sent to ethereum
SendTimestamp time.Time
Receipt *types.Receipt
Expand All @@ -99,3 +100,21 @@ type BatchInfo struct {
Fail bool
Debug Debug
}

// DebugStore is a debug function to store the BatchInfo as a json text file in
// storePath. The filename contains the batchNumber followed by a timestamp of
// batch start.
func (b *BatchInfo) DebugStore(storePath string) error {
batchJSON, err := json.MarshalIndent(b, "", " ")
if err != nil {
return common.Wrap(err)
}
// nolint reason: hardcoded 1_000_000 is the number of nanoseconds in a
// millisecond
//nolint:gomnd
filename := fmt.Sprintf("%08d-%v.%03d.json", b.BatchNum,
b.Debug.StartTimestamp.Unix(), b.Debug.StartTimestamp.Nanosecond()/1_000_000)
// nolint reason: 0640 allows rw to owner and r to group
//nolint:gosec
return ioutil.WriteFile(path.Join(storePath, filename), batchJSON, 0640)
}
Loading

0 comments on commit b1ad403

Please sign in to comment.