Merge pull request #295 from hermeznetwork/feature/integration17

Redo coordinator structure, connect API to node
This commit is contained in:
a_bennassar
2020-11-24 19:07:35 +01:00
committed by GitHub
31 changed files with 1335 additions and 763 deletions

View File

@@ -44,3 +44,28 @@ func BatchNumFromBytes(b []byte) (BatchNum, error) {
batchNum := binary.BigEndian.Uint64(b[:batchNumBytesLen])
return BatchNum(batchNum), nil
}
// BatchData contains the information of a Batch
type BatchData struct {
// L1UserTxs that were forged in the batch
L1Batch bool // TODO: Remove once Batch.ForgeL1TxsNum is a pointer
// L1UserTxs []common.L1Tx
L1CoordinatorTxs []L1Tx
L2Txs []L2Tx
CreatedAccounts []Account
ExitTree []ExitInfo
Batch Batch
}
// NewBatchData creates an empty BatchData with the slices initialized.
func NewBatchData() *BatchData {
return &BatchData{
L1Batch: false,
// L1UserTxs: make([]common.L1Tx, 0),
L1CoordinatorTxs: make([]L1Tx, 0),
L2Txs: make([]L2Tx, 0),
CreatedAccounts: make([]Account, 0),
ExitTree: make([]ExitInfo, 0),
Batch: Batch{},
}
}

View File

@@ -13,3 +13,27 @@ type Bid struct {
EthBlockNum int64 `meddler:"eth_block_num"`
Bidder ethCommon.Address `meddler:"bidder_addr"` // Coordinator reference
}
// BidCoordinator contains the coordinator info of a bid, along with the bid value
type BidCoordinator struct {
SlotNum int64 `meddler:"slot_num"`
DefaultSlotSetBid [6]*big.Int `meddler:"default_slot_set_bid,json"`
BidValue *big.Int `meddler:"bid_value,bigint"`
Bidder ethCommon.Address `meddler:"bidder_addr"` // address of the bidder
Forger ethCommon.Address `meddler:"forger_addr"` // address of the forger
URL string `meddler:"url"` // URL of the coordinators API
}
// Slot contains relevant information of a slot
type Slot struct {
SlotNum int64
DefaultSlotBid *big.Int
StartBlock int64
EndBlock int64
BatchesLen int
BidValue *big.Int
BootCoord bool
Bidder ethCommon.Address
Forger ethCommon.Address
URL string
}

View File

@@ -88,28 +88,3 @@ type BlockData struct {
// TODO: enable when common.WithdrawalDelayerVars is Merged from Synchronizer PR
// WithdrawalDelayerVars *common.WithdrawalDelayerVars
}
// BatchData contains the information of a Batch
type BatchData struct {
// L1UserTxs that were forged in the batch
L1Batch bool // TODO: Remove once Batch.ForgeL1TxsNum is a pointer
// L1UserTxs []common.L1Tx
L1CoordinatorTxs []L1Tx
L2Txs []L2Tx
CreatedAccounts []Account
ExitTree []ExitInfo
Batch Batch
}
// NewBatchData creates an empty BatchData with the slices initialized.
func NewBatchData() *BatchData {
return &BatchData{
L1Batch: false,
// L1UserTxs: make([]common.L1Tx, 0),
L1CoordinatorTxs: make([]L1Tx, 0),
L2Txs: make([]L2Tx, 0),
CreatedAccounts: make([]Account, 0),
ExitTree: make([]ExitInfo, 0),
Batch: Batch{},
}
}

View File

@@ -23,6 +23,28 @@ type AuctionConstants struct {
GovernanceAddress ethCommon.Address `json:"governanceAddress"`
}
// SlotNum returns the slot number of a block number
func (c *AuctionConstants) SlotNum(blockNum int64) int64 {
if blockNum >= c.GenesisBlockNum {
return (blockNum - c.GenesisBlockNum) / int64(c.BlocksPerSlot)
}
return -1
}
// SlotBlocks returns the first and the last block numbers included in that slot
func (c *AuctionConstants) SlotBlocks(slotNum int64) (int64, int64) {
startBlock := c.GenesisBlockNum + slotNum*int64(c.BlocksPerSlot)
endBlock := startBlock + int64(c.BlocksPerSlot) - 1
return startBlock, endBlock
}
// RelativeBlock returns the relative block number within the slot where the
// block number belongs
func (c *AuctionConstants) RelativeBlock(blockNum int64) int64 {
slotNum := c.SlotNum(blockNum)
return blockNum - (c.GenesisBlockNum + (slotNum * int64(c.BlocksPerSlot)))
}
// AuctionVariables are the variables of the Auction Smart Contract
type AuctionVariables struct {
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
@@ -32,6 +54,8 @@ type AuctionVariables struct {
BootCoordinator ethCommon.Address `json:"bootCoordinator" meddler:"boot_coordinator" validate:"required"`
// The minimum bid value in a series of 6 slots
DefaultSlotSetBid [6]*big.Int `json:"defaultSlotSetBid" meddler:"default_slot_set_bid,json" validate:"required"`
// SlotNum at which the new default_slot_set_bid applies
DefaultSlotSetBidSlotNum int64 `json:"-" meddler:"default_slot_set_bid_slot_num"`
// Distance (#slots) to the closest slot to which you can bid ( 2 Slots = 2 * 40 Blocks = 20 min )
ClosedAuctionSlots uint16 `json:"closedAuctionSlots" meddler:"closed_auction_slots" validate:"required"`
// Distance (#slots) to the farthest slot to which you can bid (30 days = 4320 slots )
@@ -48,7 +72,7 @@ type AuctionVariables struct {
func (v *AuctionVariables) Copy() *AuctionVariables {
vCpy := *v
for i := range v.DefaultSlotSetBid {
vCpy.DefaultSlotSetBid[i] = new(big.Int).SetBytes(v.DefaultSlotSetBid[i].Bytes())
vCpy.DefaultSlotSetBid[i] = CopyBigInt(v.DefaultSlotSetBid[i])
}
return &vCpy
}

View File

@@ -61,10 +61,6 @@ const (
RollupConstReservedIDx = 255
// RollupConstExitIDx IDX 1 is reserved for exits
RollupConstExitIDx = 1
// RollupConstLimitLoadAmount Max load amount allowed (loadAmount: L1 --> L2)
RollupConstLimitLoadAmount = (1 << 128)
// RollupConstLimitL2TransferAmount Max amount allowed (amount L2 --> L2)
RollupConstLimitL2TransferAmount = (1 << 192)
// RollupConstLimitTokens Max number of tokens allowed to be registered inside the rollup
RollupConstLimitTokens = (1 << 32)
// RollupConstL1CoordinatorTotalBytes [4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature
@@ -91,6 +87,11 @@ const (
)
var (
// RollupConstLimitLoadAmount Max load amount allowed (loadAmount: L1 --> L2)
RollupConstLimitLoadAmount, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10)
// RollupConstLimitL2TransferAmount Max amount allowed (amount L2 --> L2)
RollupConstLimitL2TransferAmount, _ = new(big.Int).SetString("6277101735386680763835789423207666416102355444464034512896", 10)
// RollupConstEthAddressInternalOnly This ethereum address is used internally for rollup accounts that don't have ethereum address, only Babyjubjub
// This non-ethereum accounts can be created by the coordinator and allow users to have a rollup
// account without needing an ethereum address

View File

@@ -36,3 +36,8 @@ func BJJFromStringWithChecksum(s string) (*babyjub.PublicKey, error) {
copy(pkComp[:], pkBytes[:])
return pkComp.Decompress()
}
// CopyBigInt returns a copy of the big int
func CopyBigInt(a *big.Int) *big.Int {
return new(big.Int).SetBytes(a.Bytes())
}