Skip to content

Commit

Permalink
Merge branch 'develop' into feat/pipeline-init
Browse files Browse the repository at this point in the history
  • Loading branch information
Shailu-s committed Nov 14, 2024
2 parents eda137a + be9dc7b commit 9f7ca30
Show file tree
Hide file tree
Showing 23 changed files with 574 additions and 1,121 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/sequencer.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: "SYB all tests"
on:
pull_request:
branches:
- "main"
- "develop"
paths:
- "sequencer/**"

workflow_dispatch:

jobs:
core-build:
syb-sequencer-tests:
strategy:
fail-fast: false
runs-on: ubuntu-latest
Expand Down Expand Up @@ -59,4 +59,5 @@ jobs:
PGUSER: "postgres"
PGPASSWORD: "postgres"
PGDATABASE: "statedb"
CI: true

4 changes: 3 additions & 1 deletion .github/workflows/til.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ on:
push:
branches-ignore:
- "main"
- "develop"
paths:
- "sequencer/test/til/**"
- "!sequencer/test/til/README.md"
workflow_dispatch:

jobs:
core-build:
syb-til-test:
strategy:
fail-fast: false
runs-on: ubuntu-latest
Expand Down Expand Up @@ -60,4 +61,5 @@ jobs:
PGPASSWORD: "postgres"
PGDATABASE: "statedb"
DEBUG: "true"
CI: true

38 changes: 18 additions & 20 deletions sequencer/common/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,54 @@ import (
ethCommon "github.com/ethereum/go-ethereum/common"
)

const batchNumBytesLen = 8
const batchNumBytesLen = 8 //TODO: Need to check if this needs to be updated

// Batch is a struct that represents Hermez network batch
type Batch struct {
BatchNum BatchNum `meddler:"batch_num"`
EthTxHash ethCommon.Hash `meddler:"eth_tx_hash"`
// Ethereum block in which the batch is forged
EthBlockNum int64 `meddler:"eth_block_num"`
ForgerAddr ethCommon.Address `meddler:"forger_addr"`
CollectedFees map[TokenID]*big.Int `meddler:"fees_collected,json"`
FeeIdxsCoordinator []AccountIdx `meddler:"fee_idxs_coordinator,json"`
StateRoot *big.Int `meddler:"state_root,bigint"`
NumAccounts int `meddler:"num_accounts"`
LastIdx int64 `meddler:"last_idx"`
ExitRoot *big.Int `meddler:"exit_root,bigint"`
GasUsed uint64 `meddler:"gas_used"`
GasPrice *big.Int `meddler:"gas_price,bigint"`
EtherPriceUSD float64 `meddler:"ether_price_usd"`
EthBlockNum int64 `meddler:"eth_block_num"`
ForgerAddr ethCommon.Address `meddler:"forger_addr"`
StateRoot *big.Int `meddler:"state_root,bigint"`
NumAccounts int `meddler:"num_accounts"`
LastIdx int64 `meddler:"last_idx"`
ExitRoot *big.Int `meddler:"exit_root,bigint"`
GasUsed uint64 `meddler:"gas_used"`
GasPrice *big.Int `meddler:"gas_price,bigint"`
EtherPriceUSD float64 `meddler:"ether_price_usd"`
// ForgeL1TxsNum is optional, Only when the batch forges L1 txs. Identifier that corresponds
// to the group of L1 txs forged in the current batch.
ForgeL1TxsNum *int64 `meddler:"forge_l1_txs_num"`
SlotNum int64 `meddler:"slot_num"` // Slot in which the batch is forged
TotalFeesUSD *float64 `meddler:"total_fees_usd"`
}

type BatchNum int64
type BatchNum uint32

// Bytes returns a byte array of length 4 representing the BatchNum
func (bn BatchNum) Bytes() []byte {
var batchNumBytes [batchNumBytesLen]byte
binary.BigEndian.PutUint64(batchNumBytes[:], uint64(bn))
binary.BigEndian.PutUint32(batchNumBytes[:], uint32(bn))
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 {
return 0,
Wrap(fmt.Errorf("can not parse BatchNumFromBytes, bytes len %d, expected %d",
len(b), batchNumBytesLen))
}
batchNum := binary.BigEndian.Uint64(b[:batchNumBytesLen])
batchNum := binary.BigEndian.Uint32(b[:batchNumBytesLen])
return BatchNum(batchNum), nil
}

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

// BatchData contains the information of a Batch
type BatchData struct {
L1Batch bool
Expand Down
87 changes: 85 additions & 2 deletions sequencer/common/l1tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ func (tx L1Tx) Tx() Tx {
// [ 1 bits ] empty (toBJJSign) // 1 byte
// [ 8 bits ] empty (userFee) // 1 byte
// [ 40 bits ] empty (nonce) // 5 bytes
// [ 48 bits ] toIdx // 3 bytes
// [ 48 bits ] fromIdx // 3 bytes
// [ 24 bits ] toIdx // 3 bytes
// [ 24 bits ] fromIdx // 3 bytes
// [ 16 bits ] chainId // 2 bytes
// [ 32 bits ] empty (signatureConstant) // 4 bytes
// Total bits compressed data: 225 bits // 29 bytes in *big.Int representation
Expand Down Expand Up @@ -257,6 +257,7 @@ func L1TxFromDataAvailability(b []byte, nLevels uint32) (*L1Tx, error) {
return &l1tx, Wrap(err)
}

// TODO: Remove this, In the PR to initialize the coordinator setup, pipeline creation and helper function addition
// L1CoordinatorTxFromBytes decodes a L1Tx from []byte
func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, tokamakAddress ethCommon.Address) (*L1Tx,
error) {
Expand Down Expand Up @@ -309,3 +310,85 @@ func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, tokamakAddress ethComm
}
return tx, nil
}

// BytesGeneric returns the generic representation of a L1Tx. This method is
// used to compute the []byte representation of a L1UserTx, and also to compute
// the L1TxData for the ZKInputs (at the HashGlobalInputs), using this method
// for L1CoordinatorTxs & L1UserTxs (for the ZKInputs case).
func (tx *L1Tx) BytesGeneric() ([]byte, error) {
var b [RollupConstL1UserTotalBytes]byte
copy(b[0:20], tx.FromEthAddr.Bytes())
if tx.FromBJJ != EmptyBJJComp {
pkCompL := tx.FromBJJ
pkCompB := SwapEndianness(pkCompL[:])
copy(b[20:52], pkCompB[:])
}
fromIdxBytes, err := tx.FromIdx.Bytes()
if err != nil {
return nil, Wrap(err)
}
copy(b[52:55], fromIdxBytes[:])

depositAmountFloat40, err := NewFloat40(tx.DepositAmount)
if err != nil {
return nil, Wrap(err)
}
depositAmountFloat40Bytes, err := depositAmountFloat40.Bytes()
if err != nil {
return nil, Wrap(err)
}
copy(b[58:63], depositAmountFloat40Bytes)

amountFloat40, err := NewFloat40(tx.Amount)
if err != nil {
return nil, Wrap(err)
}
amountFloat40Bytes, err := amountFloat40.Bytes()
if err != nil {
return nil, Wrap(err)
}
copy(b[63:68], amountFloat40Bytes)

//TODO: We can update this for better memory management.
// copy(b[68:72], tx.TokenID.Bytes())

toIdxBytes, err := tx.ToIdx.Bytes()
if err != nil {
return nil, Wrap(err)
}
copy(b[72:75], toIdxBytes[:])
return b[:], nil
}

// // BytesDataAvailability encodes a L1Tx into []byte for the Data Availability
// // [ fromIdx | toIdx | amountFloat40 | Fee ]
// func (tx *L1Tx) BytesDataAvailability(nLevels uint32) ([]byte, error) {
// idxLen := nLevels / 8 //nolint:gomnd

// b := make([]byte, ((nLevels*2)+40+8)/8) //nolint:gomnd

// fromIdxBytes, err := tx.FromIdx.Bytes()
// if err != nil {
// return nil, Wrap(err)
// }
// copy(b[0:idxLen], fromIdxBytes[6-idxLen:])
// toIdxBytes, err := tx.ToIdx.Bytes()
// if err != nil {
// return nil, Wrap(err)
// }
// copy(b[idxLen:idxLen*2], toIdxBytes[6-idxLen:])

// if tx.EffectiveAmount != nil {
// amountFloat40, err := NewFloat40(tx.EffectiveAmount)
// if err != nil {
// return nil, Wrap(err)
// }
// amountFloat40Bytes, err := amountFloat40.Bytes()
// if err != nil {
// return nil, Wrap(err)
// }
// copy(b[idxLen*2:idxLen*2+Float40BytesLength], amountFloat40Bytes)
// }
// // fee = 0 (as is L1Tx)
// return b[:], nil
// }
2 changes: 1 addition & 1 deletion sequencer/common/l2tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type L2Tx struct {
ToIdx AccountIdx `meddler:"to_idx"`
Nonce Nonce `meddler:"nonce"`
Type TxType `meddler:"type"`
// TODO: Amount should be removed from L2Tx struct
// TODO: Amount should be remoged from L2Tx struct
Amount *big.Int `meddler:"amount,bigint"`
// EthBlockNum in which this L2Tx was added to the queue
EthBlockNum int64 `meddler:"eth_block_num"`
Expand Down
12 changes: 0 additions & 12 deletions sequencer/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,13 @@ const (
// TxTypeExit represents L2->L1 token transfer. A leaf for this account appears in the exit
// tree of the block
TxTypeExit TxType = "Exit"
// TxTypeTransfer represents L2->L2 token transfer
TxTypeTransfer TxType = "Transfer"
// TxTypeDeposit represents L1->L2 transfer
TxTypeDeposit TxType = "Deposit"
// TxTypeCreateAccountDeposit represents creation of a new leaf in the state tree
// (newAcconut) + L1->L2 transfer
TxTypeCreateAccountDeposit TxType = "CreateAccountDeposit"
// TxTypeCreateAccountDepositTransfer represents L1->L2 transfer + L2->L2 transfer
TxTypeCreateAccountDepositTransfer TxType = "CreateAccountDepositTransfer"
// TxTypeDepositTransfer TBD
TxTypeDepositTransfer TxType = "DepositTransfer"
// TxTypeForceTransfer TBD
TxTypeForceTransfer TxType = "ForceTransfer"
// TxTypeForceExit TBD
TxTypeForceExit TxType = "ForceExit"
// TxTypeTransferToEthAddr TBD
TxTypeTransferToEthAddr TxType = "TransferToEthAddr"
// TxTypeTransferToBJJ TBD
TxTypeTransferToBJJ TxType = "TransferToBJJ"
// TxTypeCreateVouch
TxTypeCreateVouch TxType = "CreateVouch"
// TxTypeDeleteVouch
Expand Down
Loading

0 comments on commit 9f7ca30

Please sign in to comment.