mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Update to follow DB spec
This commit is contained in:
16
common/accountcreationauths.go
Normal file
16
common/accountcreationauths.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
)
|
||||
|
||||
// AccountCreationAuth authorizations sent by users to the L2DB, to be used for account creations when necessary
|
||||
type AccountCreationAuth struct {
|
||||
Timestamp time.Time
|
||||
EthAddr eth.Address
|
||||
BJJ babyjub.PublicKey
|
||||
Signature babyjub.Signature
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
@@ -9,12 +11,17 @@ type Batch struct {
|
||||
BatchNum BatchNum
|
||||
SlotNum SlotNum // Slot in which the batch is forged
|
||||
EthTxHash eth.Hash
|
||||
EthBlockNum uint64 // Etherum block in which the batch is forged
|
||||
Forger eth.Address
|
||||
EthBlockNum uint64 // Ethereum block in which the batch is forged
|
||||
ExitRoot Hash
|
||||
OldRoot Hash
|
||||
NewRoot Hash
|
||||
TotalAccounts uint64
|
||||
OldStateRoot Hash
|
||||
NewStateRoot Hash
|
||||
OldNumAccounts int
|
||||
NewNumAccounts int
|
||||
ToForgeL1TxsNum uint32 // optional, Only when the batch forges L1 txs. Identifier that corresponds to the group of L1 txs forged in the current batch.
|
||||
ToForgeL1TxsHash eth.Hash // optional, Only when the batch forges L1 txs. Frozen from pendingL1TxsHash (which are the group of L1UserTxs), to be forged in ToForgeL1TxsNum + 1.
|
||||
ForgedL1TxsHash eth.Hash // optional, Only when the batch forges L1 txs. This will be the Hash of the group of L1 txs (L1UserTxs + L1CoordinatorTx) forged in the current batch.
|
||||
CollectedFees map[TokenID]*big.Int
|
||||
ForgerAddr eth.Address // TODO: Should this be retrieved via slot reference?
|
||||
}
|
||||
|
||||
// BatchNum identifies a batch
|
||||
|
||||
@@ -5,9 +5,10 @@ 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
|
||||
InfoCoordinator Coordinator // Operaror bidder information
|
||||
Amount *big.Int
|
||||
Coordinator // Coordinator bidder information
|
||||
BidValue *big.Int
|
||||
EthBlockNum uint64
|
||||
Won bool // boolean flag that tells that this is the final winning bid of this SlotNum
|
||||
}
|
||||
|
||||
15
common/block.go
Normal file
15
common/block.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Block represents of an Ethereum block
|
||||
type Block struct {
|
||||
EthBlockNum uint64
|
||||
Timestamp time.Time
|
||||
Hash eth.Hash
|
||||
PrevHash eth.Hash
|
||||
}
|
||||
@@ -7,12 +7,8 @@ import (
|
||||
// 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
|
||||
|
||||
@@ -7,14 +7,17 @@ import (
|
||||
"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
|
||||
// L1Tx is a struct that represents a L1 tx
|
||||
type L1Tx struct {
|
||||
Tx
|
||||
UserOrigin bool // true if the tx was originated by a user, false if it was aoriginated by a coordinator. Note that this differ from the spec for implementation simplification purpposes
|
||||
PublicKey babyjub.PublicKey
|
||||
LoadAmount *big.Int // amount transfered from L1 -> L2
|
||||
EthBlockNum uint64
|
||||
EthTxHash eth.Hash
|
||||
EthBlockNum uint64 // Ethereum Block Number in which this L1Tx was added to the queue
|
||||
EthTxHash eth.Hash // TxHash that added this L1Tx to the queue
|
||||
Position int // Position among all the L1Txs in that batch
|
||||
ToForgeL1TxsNumber uint32
|
||||
ToForgeL1TxsNum uint32 // toForgeL1TxsNum in which the tx was forged / will be forged
|
||||
FromBJJ babyjub.PublicKey
|
||||
CreateAccount bool // "from" + token ID is a new account
|
||||
FromEthAddr eth.Address
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// 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
|
||||
Position int // Position among all the L1Txs in that batch
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// 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 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 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 coordinator has to bid to participate in a slot auction
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
@@ -10,13 +11,23 @@ import (
|
||||
// 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
|
||||
ToBJJ babyjub.PublicKey
|
||||
Status PoolL2TxStatus
|
||||
RqTxCompressedData []byte // 253 bits, optional for atomic txs
|
||||
RqToEthAddr eth.Address // optional for atomic txs
|
||||
RqToBjj babyjub.PublicKey // optional for atomic txs
|
||||
RqFromeEthAddr eth.Address // optional for atomic txs
|
||||
Received time.Time // time when added to the tx pool
|
||||
RqTx RqTx
|
||||
Timestamp time.Time // time when added to the tx pool
|
||||
Signature babyjub.Signature // tx signature
|
||||
ToEthAddr eth.Address
|
||||
}
|
||||
|
||||
// RqTx Transaction Data used to indicate that a transaction depends on another transaction
|
||||
type RqTx struct {
|
||||
FromEthAddr eth.Address
|
||||
ToEthAddr eth.Address
|
||||
TokenID TokenID
|
||||
Amount *big.Int
|
||||
FeeSelector FeeSelector
|
||||
Nonce uint64 // effective 48 bits used
|
||||
}
|
||||
|
||||
// PoolL2TxStatus is a struct that represents the status of a L2 transaction
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// 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 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 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
|
||||
MaxTx uint16 // Max amount of txs that can be added in a batch, either L1 or L2
|
||||
MaxL1Tx uint16 // Max amount of L1 txs that can be added in a batch
|
||||
NLevels uint16 // Heigth of the SMT. This will determine the maximum number of accounts that can coexist in the Hermez network by 2^nLevels
|
||||
}
|
||||
@@ -1,12 +1,28 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// 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
|
||||
StartingBlock uint64 // Ethereum block in which the slot starts
|
||||
Forger Coordinator // Current Operaror winner information
|
||||
}
|
||||
|
||||
// SlotMinPrice is the policy of minimum prices for strt bidding in the slots
|
||||
type SlotMinPrice struct {
|
||||
EthBlockNum uint64 // Etherum block in which the min price was updated
|
||||
MinPrices [6]big.Int
|
||||
}
|
||||
|
||||
// GetMinPrice returns the minimum bid to enter the auction for a specific slot
|
||||
func (smp *SlotMinPrice) GetMinPrice(slotNum SlotNum) *big.Int {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
// SlotNum identifies a slot
|
||||
type SlotNum uint32
|
||||
|
||||
21
common/smartcontractparams.go
Normal file
21
common/smartcontractparams.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// SmartContractParameters describes the constant values of the parameters of the Hermez smart contracts
|
||||
// WARNING: not stable at all
|
||||
type SmartContractParameters struct {
|
||||
SlotDuration uint64 // number of ethereum blocks in a slot
|
||||
Slot0BlockNum uint64 // ethereum block number of the first slot (slot 0)
|
||||
MaxL1UserTxs uint64 // maximum number of L1UserTxs that can be queued for a single batch
|
||||
FreeCoordinatorWait uint64 // if the winning coordinator doesn't forge during this number of blocks, anyone can forge
|
||||
ContractAddr eth.Address // Ethereum address of the rollup smart contract
|
||||
NLevels uint16 // Heigth of the SMT. This will determine the maximum number of accounts that can coexist in the Hermez network by 2^nLevels
|
||||
MaxTxs uint16 // Max amount of txs that can be added in a batch, either L1 or L2
|
||||
FeeL1Tx *big.Int // amount of eth (in wei) that has to be payed to do a L1 tx
|
||||
FeeDeposit *big.Int // amount of eth (in wei) that has to be payed to do a deposit
|
||||
}
|
||||
16
common/syncstate.go
Normal file
16
common/syncstate.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// SyncronizerState describes the syncronization progress of the smart contracts
|
||||
type SyncronizerState struct {
|
||||
LastUpdate time.Time // last time this information was updated
|
||||
CurrentBatchNum BatchNum // Last batch that was forged on the blockchain
|
||||
CurrentBlockNum uint64 // Last block that was mined on Ethereum
|
||||
CurrentToForgeL1TxsNum uint32
|
||||
LastSyncedBatchNum BatchNum // last batch synchronized by the coordinator
|
||||
LastSyncedBlockNum uint64 // last Ethereum block synchronized by the coordinator
|
||||
LastSyncedToForgeL1TxsNum uint32
|
||||
}
|
||||
@@ -6,12 +6,15 @@ import (
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Token is a struct that represents an Etherum token that is supported in Hermez network
|
||||
// Token is a struct that represents an Ethereum token that is supported in Hermez network
|
||||
type Token struct {
|
||||
ID TokenID
|
||||
Addr eth.Address
|
||||
TokenID TokenID
|
||||
EthAddr eth.Address
|
||||
Name string
|
||||
Symbol string
|
||||
Decimals uint64
|
||||
EthTxHash eth.Hash // Ethereum TxHash in which this token was registered
|
||||
EthBlockNum uint64 // Ethereum block number in which this token was registered
|
||||
}
|
||||
|
||||
// TokenInfo provides the price of the token in USD
|
||||
|
||||
23
common/tx.go
23
common/tx.go
@@ -2,22 +2,19 @@ package common
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
eth "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// Tx is a struct that represents a Hermez network transaction
|
||||
type Tx struct {
|
||||
ID TxID
|
||||
FromEthAddr eth.Address
|
||||
ToEthAddr eth.Address
|
||||
TxID TxID
|
||||
FromIdx uint32
|
||||
ToIdx uint32
|
||||
TokenID TokenID
|
||||
Amount *big.Int
|
||||
Nonce uint64 // effective 48 bits used
|
||||
FeeSelector FeeSelector
|
||||
Fee FeeSelector
|
||||
Type TxType // optional, descrives which kind of tx it's
|
||||
BatchNum BatchNum // batchNum in which this tx was forged. Presence indicates "forged" state.
|
||||
}
|
||||
|
||||
// TxID is the identifier of a Hermez network transaction
|
||||
@@ -37,6 +34,16 @@ const (
|
||||
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"
|
||||
// TxTypeCreateAccountDepositAndTransfer represents L1->L2 transfer + L2->L2 transfer
|
||||
TxTypeCreateAccountDepositAndTransfer TxType = "CreateAccountDepositAndTransfer"
|
||||
// TxTypeDepositAndTransfer TBD
|
||||
TxTypeDepositAndTransfer TxType = "TxTypeDepositAndTransfer"
|
||||
// TxTypeForceTransfer TBD
|
||||
TxTypeForceTransfer TxType = "TxTypeForceTransfer"
|
||||
// TxTypeForceExit TBD
|
||||
TxTypeForceExit TxType = "TxTypeForceExit"
|
||||
// TxTypeTransferToEthAddr TBD
|
||||
TxTypeTransferToEthAddr TxType = "TxTypeTransferToEthAddr"
|
||||
// TxTypeTransferToBJJ TBD
|
||||
TxTypeTransferToBJJ TxType = "TxTypeTransferToBJJ"
|
||||
)
|
||||
|
||||
10
l2db/l2db.go
10
l2db/l2db.go
@@ -56,8 +56,8 @@ func (l2db *L2DB) AddTx(tx *common.PoolL2Tx) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddRegisterAuthorization inserts a register authorization into the DB
|
||||
func (l2db *L2DB) AddRegisterAuthorization() error { // TODO: AddRegisterAuthorization(auth &common.RegisterAuthorization)
|
||||
// AddAccountCreationAuth inserts an account creation authorization into the DB
|
||||
func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error { // TODO: AddRegisterAuthorization(auth &common.RegisterAuthorization)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ func (l2db *L2DB) GetPendingTxs() ([]common.PoolL2Tx, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetRegisterAuthorization return the authorization to make registers of an Etherum address
|
||||
func (l2db *L2DB) GetRegisterAuthorization(ethAddr eth.Address) (int, error) { // TODO: int will be changed to *common.RegisterAuthorization
|
||||
return 0, nil
|
||||
// GetAccountCreationAuth return the authorization to make registers of an Ethereum address
|
||||
func (l2db *L2DB) GetAccountCreationAuth(ethAddr eth.Address) (*common.AccountCreationAuth, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// StartForging updates the state of the transactions that will begin the forging process.
|
||||
|
||||
Reference in New Issue
Block a user