Skip to content

Commit

Permalink
Updated coordinator pipeline and batch initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Shailu-s committed Nov 20, 2024
1 parent 9f7ca30 commit 7306e0b
Show file tree
Hide file tree
Showing 8 changed files with 897 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/historydb.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:
PGUSER: "postgres"
PGPASSWORD: "postgres"
PGDATABASE: "statedb"
CI: true
CI: true
10 changes: 10 additions & 0 deletions sequencer/common/atomic.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package common

// AtomicGroup represents a set of atomic transactions
type AtomicGroup struct {
ID AtomicGroupID `json:"atomicGroupId"`
Txs []PoolL2Tx `json:"transactions"`
}

// AtomicGroupIDLen is the length of a Hermez network atomic group
const AtomicGroupIDLen = 32

// AtomicGroupID is the identifier of a Hermez network atomic group
type AtomicGroupID [AtomicGroupIDLen]byte

// EmptyAtomicGroupID represents an empty Hermez network atomic group identifier
var EmptyAtomicGroupID = AtomicGroupID([32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
7 changes: 2 additions & 5 deletions sequencer/common/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ type Batch struct {
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"`
ForgeL1TxsNum *int64 `meddler:"forge_l1_txs_num"`
SlotNum int64 `meddler:"slot_num"` // Slot in which the batch is forged
}

type BatchNum uint32
Expand Down
64 changes: 32 additions & 32 deletions sequencer/common/l1tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,35 +360,35 @@ func (tx *L1Tx) BytesGeneric() ([]byte, error) {
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
// }
// 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
}
33 changes: 33 additions & 0 deletions sequencer/common/l2tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,36 @@ func L2TxFromBytesDataAvailability(b []byte, nLevels int) (*L2Tx, error) {
// tx.Fee = FeeSelector(b[idxLen*2+Float40BytesLength])
return tx, nil
}

// BytesDataAvailability encodes a L2Tx into []byte for the Data Availability
// [ fromIdx | toIdx | amountFloat40 | Fee ]
func (tx L2Tx) 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:]) // [6-idxLen:] as is BigEndian

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

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[idxLen*2:idxLen*2+Float40BytesLength], amountFloat40Bytes)
// b[idxLen*2+Float40BytesLength] = byte(tx.Fee)

return b[:], nil
}
Loading

0 comments on commit 7306e0b

Please sign in to comment.