arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Review changes and operator -> coordinator
a_bennassar arnaubennassar5@gmail.com
Tue, 28 Jul 2020 16:47:37 +0200
commit

1d8f9411f7c8e7016d49230f9641864853856bab

parent

b9936f856427ef2268fb716b3ce7986b32516f46

M common/account.go → common/account.go

@@ -14,5 +14,5 @@ TokenID TokenID // effective 32 bits

Idx uint32 // bits = SMT levels (SMT levels needs to be decided) Nonce uint64 // effective 48 bits Balance *big.Int // Up to 192 bits - Signature babyjub.PublicKey + PublicKey babyjub.PublicKey }
M common/batch.go → common/batch.go

@@ -1,8 +1,6 @@

package common import ( - "time" - eth "github.com/ethereum/go-ethereum/common" )

@@ -11,8 +9,7 @@ type Batch struct {

BatchNum BatchNum SlotNum SlotNum // Slot in which the batch is forged EthTxHash eth.Hash - BlockNum uint64 // Etherum block in which the batch is forged - Timestamp time.Time + EthBlockNum uint64 // Etherum block in which the batch is forged Forger eth.Address ExitRoot Hash OldRoot Hash
M common/bid.go → common/bid.go

@@ -7,7 +7,7 @@

// Bid is a struct that represents one bid in the PoH // WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot. type Bid struct { - SlotNum SlotNum // Slot in which the bid is done - InfoOperator Operator // Operaror bidder information - Amount *big.Int + SlotNum SlotNum // Slot in which the bid is done + InfoCoordinator Coordinator // Operaror bidder information + Amount *big.Int }
A common/coordinator.go

@@ -0,0 +1,18 @@

+package common + +import ( + eth "github.com/ethereum/go-ethereum/common" +) + +// Coordinator represents a Hermez network coordinator who wins an auction for an specific slot +// WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot. +type Coordinator struct { + CoordinatorID CoordinatorID + Forger eth.Address // address of the forger + Beneficiary eth.Address // address of the beneficiary + Withdraw eth.Address // address of the withdraw + URL string // URL of the coordinators API +} + +// CoordinatorID is use to identify a Hermez coordinator +type CoordinatorID uint64
M common/fee.go → common/fee.go

@@ -12,25 +12,8 @@ CreatesAccount float64

CreatesAccountAndRegister float64 } -// FeeSelector is used to select a percentage from the FeePlan. Max value is 16 +// FeeSelector is used to select a percentage from the FeePlan. type FeeSelector uint8 // FeePlan represents the fee model, a position in the array indicates the percentage of tokens paid in concept of fee for a transaction -var FeePlan = [16]float64{ - 0, - .001, - .002, - .005, - .01, - .02, - .05, - .1, - .2, - .5, - 1, - 2, - 5, - 10, - 20, - 50, -} +var FeePlan = [256]float64{}
M common/l1tx.go → common/l1tx.go

@@ -1,15 +1,20 @@

package common -import "math/big" +import ( + "math/big" + + eth "github.com/ethereum/go-ethereum/common" + "github.com/iden3/go-iden3-crypto/babyjub" +) // L1Tx is a struct that represents an already forged L1 tx // WARNING: this struct is very unclear and a complete guess type L1Tx struct { Tx - Ax *big.Int // Ax is the x coordinate of the BabyJubJub curve point - Ay *big.Int // Ay is the y coordinate of the BabyJubJub curve point + PublicKey babyjub.PublicKey LoadAmount *big.Int // amount transfered from L1 -> L2 - Mined bool - BlockNum uint64 + EthBlockNum uint64 + EthTxHash eth.Hash + Position int // Position among all the L1Txs in that batch ToForgeL1TxsNumber uint32 }
M common/l2tx.go → common/l2tx.go

@@ -8,5 +8,6 @@ // L2Tx is a struct that represents an already forged L2 tx

type L2Tx struct { Tx Forged time.Time // time when received by the tx pool - BatchNum BatchNum // Batch in which the tx was forged, 0 means not forged + BatchNum BatchNum // Batch in which the tx was forged + Position int // Position among all the L1Txs in that batch }
D common/operator.go

@@ -1,14 +0,0 @@

-package common - -import ( - eth "github.com/ethereum/go-ethereum/common" -) - -// Operator represents a Hermez network operator who wins an auction for an specific slot -// WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot. -type Operator struct { - Forger eth.Address // address of the forger - Beneficiary eth.Address // address of the beneficiary - Withdraw eth.Address // address of the withdraw - URL string // URL of the operators API -}
M common/pohstate.go → common/pohstate.go

@@ -6,15 +6,15 @@

eth "github.com/ethereum/go-ethereum/common" ) -// PoHState give information about the forging mechanism of the Hermez network, and the synchronization status between the operator and the smart contract +// PoHState give information about the forging mechanism of the Hermez network, and the synchronization status between the coordinator and the smart contract // WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot. type PoHState struct { - IsSynched bool // true if the operator is fully synched with the ¿PoH? smart contract + IsSynched bool // true if the coordinator is fully synched with the ¿PoH? smart contract SyncProgress float32 // percentage of synced progress with the ¿PoH? smart contract CurrentSlot SlotNum // slot in which batches are being forged at the current time ContractAddr eth.Address // Etherum address of the ¿PoH? smart contract BlocksPerSlot uint16 // Slot duration measured in Etherum blocks - SlotDeadline uint16 // Time of the slot in which another operator can forge if the operator winner has not forge any block before + SlotDeadline uint16 // Time of the slot in which another coordinator can forge if the coordinator winner has not forge any block before GenesisBlock uint64 // uint64 is a guess, Etherum block in which the ¿PoH? contract was deployed - MinBid *big.Int // Minimum amount that an operator has to bid to participate in a slot auction + MinBid *big.Int // Minimum amount that an coordinator has to bid to participate in a slot auction }
M common/pooll2tx.go → common/pooll2tx.go

@@ -7,7 +7,7 @@ eth "github.com/ethereum/go-ethereum/common"

"github.com/iden3/go-iden3-crypto/babyjub" ) -// PoolL2Tx is a struct that represents a L2Tx sent by an account to the operator hat is waiting to be forged +// PoolL2Tx is a struct that represents a L2Tx sent by an account to the coordinator hat is waiting to be forged type PoolL2Tx struct { Tx Status PoolL2TxStatus

@@ -23,12 +23,12 @@ // PoolL2TxStatus is a struct that represents the status of a L2 transaction

type PoolL2TxStatus string const ( - // Pending represents a valid L2Tx that hasn't started the forging process - Pending PoolL2TxStatus = "Pending" - // Forging represents a valid L2Tx that has started the forging process - Forging PoolL2TxStatus = "Forging" - // Forged represents a L2Tx that has already been forged - Forged PoolL2TxStatus = "Forged" - // Invalid represents a L2Tx that has been invalidated - Invalid PoolL2TxStatus = "Invalid" + // PoolL2TxStatusPending represents a valid L2Tx that hasn't started the forging process + PoolL2TxStatusPending PoolL2TxStatus = "Pending" + // PoolL2TxStatusForging represents a valid L2Tx that has started the forging process + PoolL2TxStatusForging PoolL2TxStatus = "Forging" + // PoolL2TxStatusForged represents a L2Tx that has already been forged + PoolL2TxStatusForged PoolL2TxStatus = "Forged" + // PoolL2TxStatusInvalid represents a L2Tx that has been invalidated + PoolL2TxStatusInvalid PoolL2TxStatus = "Invalid" )
M common/rollupstate.go → common/rollupstate.go

@@ -6,12 +6,12 @@

eth "github.com/ethereum/go-ethereum/common" ) -// RollupState give information about the rollup, and the synchronization status between the operator and the smart contract +// RollupState give information about the rollup, and the synchronization status between the coordinator and the smart contract type RollupState struct { - IsSynched bool // true if the operator is fully synched with the rollup smart contract + IsSynched bool // true if the coordinator is fully synched with the rollup smart contract SyncProgress float32 // percentage of synced progress with the rollup smart contract - LastBlockSynched uint64 // last Etherum block synchronized by the operator - LastBatchSynched BatchNum // last batch synchronized by the operator + LastBlockSynched uint64 // last Etherum block synchronized by the coordinator + LastBatchSynched BatchNum // last batch synchronized by the coordinator FeeDeposit *big.Int // amount of eth (in wei) that has to be payed to do a deposit FeeL1Tx *big.Int // amount of eth (in wei) that has to be payed to do a L1 tx ContractAddr eth.Address // Etherum address of the rollup smart contract
M common/slot.go → common/slot.go

@@ -4,8 +4,8 @@ // Slot represents a slot of the Hermez network

// WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot. type Slot struct { SlotNum SlotNum - StartingBlock uint64 // Etherum block in which the slot starts - Forger Operator // Current Operaror winner information + StartingBlock uint64 // Etherum block in which the slot starts + Forger Coordinator // Current Operaror winner information } // SlotNum identifies a slot
M common/tx.go → common/tx.go

@@ -27,16 +27,16 @@ // TxType is a string that represents the type of a Hermez network transaction

type TxType string const ( - // Exit represents L2->L1 token transfer. A leaf for this account appears in the exit tree of the block - Exit TxType = "Exit" - // Withdrawn represents the balance that was moved from L2->L1 has been widthrawn from the smart contract - Withdrawn TxType = "Withdrawn" - // Transfer represents L2->L2 token transfer - Transfer TxType = "Transfer" - // Deposit represents L1->L2 transfer - Deposit TxType = "Deposit" - // CreateAccountDeposit represents creation of a new leaf in the state tree (newAcconut) + L1->L2 transfer - CreateAccountDeposit TxType = "CreateAccountDeposit" - // CreateAccountDepositTransfer represents L1->L2 transfer + L2->L2 transfer - CreateAccountDepositTransfer TxType = "CreateAccountDepositTransfer" + // TxTypeExit represents L2->L1 token transfer. A leaf for this account appears in the exit tree of the block + TxTypeExit TxType = "Exit" + // TxTypeWithdrawn represents the balance that was moved from L2->L1 has been widthrawn from the smart contract + TxTypeWithdrawn TxType = "Withdrawn" + // 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" )