Browse Source

Review changes and operator -> coordinator

feature/sql-semaphore1
a_bennassar 4 years ago
parent
commit
1d8f9411f7
13 changed files with 68 additions and 78 deletions
  1. +1
    -1
      common/account.go
  2. +1
    -4
      common/batch.go
  3. +3
    -3
      common/bid.go
  4. +18
    -0
      common/coordinator.go
  5. +2
    -19
      common/fee.go
  6. +10
    -5
      common/l1tx.go
  7. +2
    -1
      common/l2tx.go
  8. +0
    -14
      common/operator.go
  9. +4
    -4
      common/pohstate.go
  10. +9
    -9
      common/pooll2tx.go
  11. +4
    -4
      common/rollupstate.go
  12. +2
    -2
      common/slot.go
  13. +12
    -12
      common/tx.go

+ 1
- 1
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
}

+ 1
- 4
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

+ 3
- 3
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
}

+ 18
- 0
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

+ 2
- 19
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{}

+ 10
- 5
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
}

+ 2
- 1
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
}

+ 0
- 14
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
}

+ 4
- 4
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
}

+ 9
- 9
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"
)

+ 4
- 4
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

+ 2
- 2
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

+ 12
- 12
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"
)

Loading…
Cancel
Save