From 1d8f9411f7c8e7016d49230f9641864853856bab Mon Sep 17 00:00:00 2001 From: a_bennassar Date: Tue, 28 Jul 2020 16:47:37 +0200 Subject: [PATCH] Review changes and operator -> coordinator --- common/account.go | 2 +- common/batch.go | 5 +---- common/bid.go | 6 +++--- common/coordinator.go | 18 ++++++++++++++++++ common/fee.go | 21 ++------------------- common/l1tx.go | 15 ++++++++++----- common/l2tx.go | 3 ++- common/operator.go | 14 -------------- common/pohstate.go | 8 ++++---- common/pooll2tx.go | 18 +++++++++--------- common/rollupstate.go | 8 ++++---- common/slot.go | 4 ++-- common/tx.go | 24 ++++++++++++------------ 13 files changed, 68 insertions(+), 78 deletions(-) create mode 100644 common/coordinator.go delete mode 100644 common/operator.go diff --git a/common/account.go b/common/account.go index 248e463..652a4ac 100644 --- a/common/account.go +++ b/common/account.go @@ -14,5 +14,5 @@ type Account struct { 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 } diff --git a/common/batch.go b/common/batch.go index f8af15a..c9f94a2 100644 --- a/common/batch.go +++ b/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 diff --git a/common/bid.go b/common/bid.go index 0ea8551..3fcade0 100644 --- a/common/bid.go +++ b/common/bid.go @@ -7,7 +7,7 @@ import ( // 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 } diff --git a/common/coordinator.go b/common/coordinator.go new file mode 100644 index 0000000..73b714a --- /dev/null +++ b/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 diff --git a/common/fee.go b/common/fee.go index a4d5914..da3314f 100644 --- a/common/fee.go +++ b/common/fee.go @@ -12,25 +12,8 @@ type RecommendedFee struct { 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{} diff --git a/common/l1tx.go b/common/l1tx.go index d406aa5..8b27cbb 100644 --- a/common/l1tx.go +++ b/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 } diff --git a/common/l2tx.go b/common/l2tx.go index d6e54bf..3f8c3a2 100644 --- a/common/l2tx.go +++ b/common/l2tx.go @@ -8,5 +8,6 @@ import ( 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 } diff --git a/common/operator.go b/common/operator.go deleted file mode 100644 index 06750d9..0000000 --- a/common/operator.go +++ /dev/null @@ -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 -} diff --git a/common/pohstate.go b/common/pohstate.go index 6a14f5d..3886ed8 100644 --- a/common/pohstate.go +++ b/common/pohstate.go @@ -6,15 +6,15 @@ import ( 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 } diff --git a/common/pooll2tx.go b/common/pooll2tx.go index d3b534d..0b1d3e5 100644 --- a/common/pooll2tx.go +++ b/common/pooll2tx.go @@ -7,7 +7,7 @@ import ( "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 @@ type PoolL2Tx struct { 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" ) diff --git a/common/rollupstate.go b/common/rollupstate.go index 8ad1930..1b4ff48 100644 --- a/common/rollupstate.go +++ b/common/rollupstate.go @@ -6,12 +6,12 @@ import ( 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 diff --git a/common/slot.go b/common/slot.go index e750c46..8ad22fc 100644 --- a/common/slot.go +++ b/common/slot.go @@ -4,8 +4,8 @@ package common // 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 diff --git a/common/tx.go b/common/tx.go index 98d4fb9..132fcfd 100644 --- a/common/tx.go +++ b/common/tx.go @@ -27,16 +27,16 @@ type TxID Hash // Hash is a guess 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" )