@ -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,20 +1,27 @@ |
|||||
package common |
package common |
||||
|
|
||||
import ( |
import ( |
||||
|
"math/big" |
||||
|
|
||||
eth "github.com/ethereum/go-ethereum/common" |
eth "github.com/ethereum/go-ethereum/common" |
||||
) |
) |
||||
|
|
||||
// Batch is a struct that represents Hermez network batch
|
// Batch is a struct that represents Hermez network batch
|
||||
type Batch struct { |
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 |
|
||||
ExitRoot Hash |
|
||||
OldRoot Hash |
|
||||
NewRoot Hash |
|
||||
TotalAccounts uint64 |
|
||||
|
BatchNum BatchNum |
||||
|
SlotNum SlotNum // Slot in which the batch is forged
|
||||
|
EthTxHash eth.Hash |
||||
|
EthBlockNum uint64 // Ethereum block in which the batch is forged
|
||||
|
ExitRoot Hash |
||||
|
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
|
// BatchNum identifies a batch
|
||||
|
@ -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 |
||||
|
} |
@ -1,13 +1,7 @@ |
|||||
package common |
package common |
||||
|
|
||||
import ( |
|
||||
"time" |
|
||||
) |
|
||||
|
|
||||
// L2Tx is a struct that represents an already forged L2 tx
|
// L2Tx is a struct that represents an already forged L2 tx
|
||||
type L2Tx struct { |
type L2Tx struct { |
||||
Tx |
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
|
|
||||
|
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,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 |
package common |
||||
|
|
||||
|
import ( |
||||
|
"math/big" |
||||
|
) |
||||
|
|
||||
// Slot represents a slot of the Hermez network
|
// 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.
|
// WARNING: this is strongly based on the previous implementation, once the new spec is done, this may change a lot.
|
||||
type Slot struct { |
type Slot struct { |
||||
SlotNum SlotNum |
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
|
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
|
// SlotNum identifies a slot
|
||||
type SlotNum uint32 |
type SlotNum uint32 |
@ -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
|
||||
|
} |
@ -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 |
||||
|
} |