Browse Source

Add config endpoint

feature/sql-semaphore1
laisolizq 4 years ago
parent
commit
f90de219ac
8 changed files with 253 additions and 83 deletions
  1. +3
    -0
      api/api.go
  2. +53
    -0
      api/api_test.go
  3. +28
    -0
      api/dbtoapistructs.go
  4. +1
    -1
      api/handlers.go
  5. +150
    -64
      api/swagger.yml
  6. +6
    -6
      eth/auction.go
  7. +9
    -9
      eth/rollup.go
  8. +3
    -3
      eth/wdelayer.go

+ 3
- 0
api/api.go

@ -10,6 +10,7 @@ import (
) )
var h *historydb.HistoryDB var h *historydb.HistoryDB
var cg *configAPI
// var s *statedb.StateDB // Not 100% sure if this is needed // var s *statedb.StateDB // Not 100% sure if this is needed
// var l2 *l2db.L2DB // var l2 *l2db.L2DB
@ -21,6 +22,7 @@ func SetAPIEndpoints(
hdb *historydb.HistoryDB, hdb *historydb.HistoryDB,
sdb *statedb.StateDB, sdb *statedb.StateDB,
l2db *l2db.L2DB, l2db *l2db.L2DB,
config *configAPI,
) error { ) error {
// Check input // Check input
// TODO: is stateDB only needed for explorer endpoints or for both? // TODO: is stateDB only needed for explorer endpoints or for both?
@ -32,6 +34,7 @@ func SetAPIEndpoints(
} }
h = hdb h = hdb
cg = config
// s = sdb // s = sdb
// l2 = l2db // l2 = l2db

+ 53
- 0
api/api_test.go

@ -24,6 +24,7 @@ import (
"github.com/hermeznetwork/hermez-node/db/historydb" "github.com/hermeznetwork/hermez-node/db/historydb"
"github.com/hermeznetwork/hermez-node/db/l2db" "github.com/hermeznetwork/hermez-node/db/l2db"
"github.com/hermeznetwork/hermez-node/db/statedb" "github.com/hermeznetwork/hermez-node/db/statedb"
"github.com/hermeznetwork/hermez-node/eth"
"github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/hermez-node/log"
"github.com/hermeznetwork/hermez-node/test" "github.com/hermeznetwork/hermez-node/test"
"github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-iden3-crypto/babyjub"
@ -130,6 +131,7 @@ func (tx *wrappedL2) L2() *common.L2Tx {
} }
var tc testCommon var tc testCommon
var config configAPI
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
// Init swagger // Init swagger
@ -159,6 +161,48 @@ func TestMain(m *testing.M) {
l2DB := l2db.NewL2DB(database, 10, 100, 24*time.Hour) l2DB := l2db.NewL2DB(database, 10, 100, 24*time.Hour)
test.CleanL2DB(l2DB.DB()) test.CleanL2DB(l2DB.DB())
config.RollupConstants.ExchangeMultiplier = eth.RollupConstExchangeMultiplier
config.RollupConstants.ExitIdx = eth.RollupConstExitIDx
config.RollupConstants.ReservedIdx = eth.RollupConstReservedIDx
config.RollupConstants.LimitLoadAmount, _ = new(big.Int).SetString("340282366920938463463374607431768211456", 10)
config.RollupConstants.LimitL2TransferAmount, _ = new(big.Int).SetString("6277101735386680763835789423207666416102355444464034512896", 10)
config.RollupConstants.LimitTokens = eth.RollupConstLimitTokens
config.RollupConstants.L1CoordinatorTotalBytes = eth.RollupConstL1CoordinatorTotalBytes
config.RollupConstants.L1UserTotalBytes = eth.RollupConstL1UserTotalBytes
config.RollupConstants.MaxL1UserTx = eth.RollupConstMaxL1UserTx
config.RollupConstants.MaxL1Tx = eth.RollupConstMaxL1Tx
config.RollupConstants.InputSHAConstantBytes = eth.RollupConstInputSHAConstantBytes
config.RollupConstants.NumBuckets = eth.RollupConstNumBuckets
config.RollupConstants.MaxWithdrawalDelay = eth.RollupConstMaxWithdrawalDelay
var rollupPublicConstants eth.RollupPublicConstants
rollupPublicConstants.AbsoluteMaxL1L2BatchTimeout = 240
rollupPublicConstants.HermezAuctionContract = ethCommon.HexToAddress("0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e")
rollupPublicConstants.HermezGovernanceDAOAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4")
rollupPublicConstants.SafetyAddress = ethCommon.HexToAddress("0xE5904695748fe4A84b40b3fc79De2277660BD1D3")
rollupPublicConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB")
rollupPublicConstants.WithdrawDelayerContract = ethCommon.HexToAddress("0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe")
var verifier eth.RollupVerifierStruct
verifier.MaxTx = 512
verifier.NLevels = 32
rollupPublicConstants.Verifiers = append(rollupPublicConstants.Verifiers, verifier)
var auctionConstants eth.AuctionConstants
auctionConstants.BlocksPerSlot = 40
auctionConstants.GenesisBlockNum = 100
auctionConstants.GovernanceAddress = ethCommon.HexToAddress("0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4")
auctionConstants.InitialMinimalBidding, _ = new(big.Int).SetString("10000000000000000000", 10)
auctionConstants.HermezRollup = ethCommon.HexToAddress("0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0")
auctionConstants.TokenHEZ = ethCommon.HexToAddress("0xf784709d2317D872237C4bC22f867d1BAe2913AB")
var wdelayerConstants eth.WDelayerConstants
wdelayerConstants.HermezRollup = ethCommon.HexToAddress("0xEa960515F8b4C237730F028cBAcF0a28E7F45dE0")
wdelayerConstants.MaxEmergencyModeTime = uint64(1000000)
wdelayerConstants.MaxWithdrawalDelay = uint64(10000000)
config.RollupConstants.PublicConstants = rollupPublicConstants
config.AuctionConstants = auctionConstants
config.WDelayerConstants = wdelayerConstants
// Init API // Init API
api := gin.Default() api := gin.Default()
if err := SetAPIEndpoints( if err := SetAPIEndpoints(
@ -168,6 +212,7 @@ func TestMain(m *testing.M) {
hdb, hdb,
sdb, sdb,
l2DB, l2DB,
&config,
); err != nil { ); err != nil {
panic(err) panic(err)
} }
@ -991,6 +1036,14 @@ func assertTokensAPIs(t *testing.T, expected, actual []tokenAPI) {
} }
} }
func TestGetConfig(t *testing.T) {
endpoint := apiURL + "config"
var configTest configAPI
assert.NoError(t, doGoodReq("GET", endpoint, nil, &configTest))
assert.Equal(t, config, configTest)
assert.Equal(t, cg, &configTest)
}
func doGoodReqPaginated( func doGoodReqPaginated(
path, order string, path, order string,
iterStruct db.Paginationer, iterStruct db.Paginationer,

+ 28
- 0
api/dbtoapistructs.go

@ -2,6 +2,7 @@ package api
import ( import (
"encoding/base64" "encoding/base64"
"math/big"
"strconv" "strconv"
"time" "time"
@ -9,6 +10,7 @@ import (
"github.com/hermeznetwork/hermez-node/common" "github.com/hermeznetwork/hermez-node/common"
"github.com/hermeznetwork/hermez-node/db" "github.com/hermeznetwork/hermez-node/db"
"github.com/hermeznetwork/hermez-node/db/historydb" "github.com/hermeznetwork/hermez-node/db/historydb"
"github.com/hermeznetwork/hermez-node/eth"
"github.com/iden3/go-iden3-crypto/babyjub" "github.com/iden3/go-iden3-crypto/babyjub"
"github.com/iden3/go-merkletree" "github.com/iden3/go-merkletree"
) )
@ -248,3 +250,29 @@ func tokensToAPI(dbTokens []historydb.TokenRead) []tokenAPI {
} }
return apiTokens return apiTokens
} }
// Config
type rollupConstants struct {
PublicConstants eth.RollupPublicConstants `json:"publicConstants"`
MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"`
ReservedIdx int `json:"reservedIdx"`
ExitIdx int `json:"exitIdx"`
LimitLoadAmount *big.Int `json:"limitLoadAmount"`
LimitL2TransferAmount *big.Int `json:"limitL2TransferAmount"`
LimitTokens int `json:"limitTokens"`
L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"`
L1UserTotalBytes int `json:"l1UserTotalBytes"`
MaxL1UserTx int `json:"maxL1UserTx"`
MaxL1Tx int `json:"maxL1Tx"`
InputSHAConstantBytes int `json:"inputSHAConstantBytes"`
NumBuckets int `json:"numBuckets"`
MaxWithdrawalDelay int `json:"maxWithdrawalDelay"`
ExchangeMultiplier int `json:"exchangeMultiplier"`
}
type configAPI struct {
RollupConstants rollupConstants `json:"hermez"`
AuctionConstants eth.AuctionConstants `json:"auction"`
WDelayerConstants eth.WDelayerConstants `json:"withdrawalDelayer"`
}

+ 1
- 1
api/handlers.go

@ -198,7 +198,7 @@ func getState(c *gin.Context) {
} }
func getConfig(c *gin.Context) { func getConfig(c *gin.Context) {
c.JSON(http.StatusOK, cg)
} }
func getTokens(c *gin.Context) { func getTokens(c *gin.Context) {

+ 150
- 64
api/swagger.yml

@ -2330,104 +2330,175 @@ components:
type: object type: object
description: Constant configuration of the Hermez smart contract. description: Constant configuration of the Hermez smart contract.
properties: properties:
HEZTokenAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the HEZ token.
- example: "0x444dc4262BCDbf85190C01c996b4C06a461d2430"
maxTxVerifiers:
publicConstants:
type: object
description: Public Hermez smart contract constants
properties:
tokenHEZ:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the HEZ token.
- example: "0x444dc4262BCDbf85190C01c996b4C06a461d2430"
absoluteMaxL1L2BatchTimeout:
type: integer
description: L1L2 Batch Timeout
example: 240
verifiers:
type: array
description: List of verifiers struct
items:
type: object
properties:
maxTx:
type: integer
description: Maximum rollup transactions in a batch
example: 512
nlevels:
type: integer
description: Number of levels of the circuit
example: 32
required:
- maxTx
- nlevels
additionalProperties: false
hermezAuctionContract:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the auction smart contract.
- example: "0x111dc4262BCDbf85190C01c996b4C06a461d2430"
hermezGovernanceDAOAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the governanceDAO.
- example: "0x222dc4262BCDbf85190C01c996b4C06a461d2430"
safetyAddress:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the safety.
- example: "0x333dc4262BCDbf85190C01c996b4C06a461d2430"
withdrawDelayerContract:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the withdraw delayer contracts.
- example: "0x444dc4262BCDbf85190C01c996b4C06a461d2430"
required:
- tokenHEZ
- absoluteMaxL1L2BatchTimeout
- verifiers
- hermezAuctionContract
- hermezGovernanceDAOAddress
- safetyAddress
- withdrawDelayerContract
additionalProperties: false
maxFeeIdxCoordinator:
type: integer type: integer
description: Maximum transactions of the verifiers.
example: 100
maxLoadAmount:
description: is the maximum number of tokens the coordinator can use to collect fees.
example: 64
reservedIdx:
type: integer
description: First 256 indexes reserved, first user index will be the 256.
example: 255
exitIdx:
type: integer
description: Account index used to indicate that a transaction is an `exit` or `force exit`.
example: 1
limitLoadAmount:
type: integer type: integer
description: Maximum load amount (L1 to L2) allowed. description: Maximum load amount (L1 to L2) allowed.
example: 321 example: 321
maxAmount:
limitL2TransferAmount:
type: integer type: integer
description: Maximum amount (L2 to L2) allowed. description: Maximum amount (L2 to L2) allowed.
example: 837 example: 837
maxTokens:
limitTokens:
type: integer type: integer
description: Maximum number of different tokens that can be registered in the network. description: Maximum number of different tokens that can be registered in the network.
example: 4294967295 example: 4294967295
reservedAccountIndex:
type: integer
description: First user index. Bellow this number the indexes are reserved for the protocol.
example: 256
lastAccountIndex:
type: integer
description: Biggest account index that can be registered.
example: 4294967295
exitAccountIndex:
type: integer
description: Account index used to indicate that a transaction is an `exit` or `force exit`.
example: 1
L1CoordinatorBytes:
l1CoordinatorTotalBytes:
type: integer type: integer
description: Number of bytes that a L1 coordinator transaction has ([4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature). description: Number of bytes that a L1 coordinator transaction has ([4 bytes] token + [32 bytes] babyjub + [65 bytes] compressedSignature).
example: 23
L1UserBytes:
type: integer
description: Number of bytes that a L2 transaction has ([4 bytes] fromIdx + [4 bytes] toIdx + [2 bytes] amountFloat16 + [1 bytes] fee).
example: 32
L2Bytes:
example: 101
l1UserTotalBytes:
type: integer type: integer
description: Number of bytes that a L2 transaction has ([4 bytes] fromIdx + [4 bytes] toIdx + [2 bytes] amountFloat16 + [1 bytes] fee).
example: 33
maxL1Transactions:
description: Number of bytes that a L1 user transaction has ([20 bytes] fromEthAddr + [32 bytes] fromBjj-compressed + [6 bytes] fromIdx + [2 bytes] loadAmountFloat16 + [2 bytes] amountFloat16 + [4 bytes] tokenId + [6 bytes] toIdx).
example: 72
maxL1UserTx:
type: integer type: integer
description: Maximum L1 transactions allowed to be queued in a batch.
description: Maximum L1-user transactions allowed to be queued in a batch.
example: 128 example: 128
maxL1UserTransactions:
maxL1Tx:
type: integer type: integer
description: Maximum L1 transactions allowed to be queued in a batch by users (anyone who is not a coordinator).
example: 32
RField:
allOf:
- $ref: '#/components/schemas/BigInt'
- description: Modulus zkSNARK.
withdrawManager:
type: object
description: Constant configuration of the withdraw manager smart contract.
properties:
noLimit:
description: Maximum L1 transactions allowed to be queued in a batch.
example: 256
inputSHAConstantBytes:
type: integer type: integer
description: Reserved bucket index when the token value is 0 USD.
example: 0
amountOfBuckets:
description: Input SHA constant bytes
example: 18542
numBuckets:
type: integer type: integer
description: Number of buckets description: Number of buckets
example: 5
maxWithdrawalDelay: maxWithdrawalDelay:
type: integer type: integer
description: Maximum delay to withdraw tokens. Time is measured in Ethereum blocks.
description: Maximum delay to withdraw tokens. Time is measured in seconds.
example: 2 * 7 * 24 * 60 * 60
exchangeMultiplier:
type: integer
description: exchange multiplier
example: 1e14
required:
- publicConstants
- reservedIdx
- exitIdx
- limitLoadAmount
- limitL2TransferAmount
- limitTokens
- l1CoordinatorTotalBytes
- l1UserTotalBytes
- maxL1UserTx
- maxL1Tx
- inputSHAConstantBytes
- numBuckets
- maxWithdrawalDelay
- exchangeMultiplier
additionalProperties: false
auction: auction:
type: object type: object
description: Constant configuration of the auction smart contract. description: Constant configuration of the auction smart contract.
properties: properties:
HEZTokenAddress:
blocksPerSlot:
type: integer
description: Blocks per slot.
initialMinimalBidding:
type: integer
description: Minimum bid when no one has bid yet.
genesisBlockNum:
allOf:
- $ref: '#/components/schemas/EthBlockNum'
- description: Ethereum block number in which the smart contract starts operating.
tokenHEZ:
allOf: allOf:
- $ref: '#/components/schemas/EthereumAddress' - $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the HEZ token. - description: Ethereum address of the HEZ token.
- example: "0x333dc4262BCDbf85190C01c996b4C06a461d2430" - example: "0x333dc4262BCDbf85190C01c996b4C06a461d2430"
rollupAddress:
hermezRollup:
allOf: allOf:
- $ref: '#/components/schemas/EthereumAddress' - $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the rollup smart contract. - description: Ethereum address of the rollup smart contract.
- example: "0x222dc4262BCDbf85190C01c996b4C06a461d2430" - example: "0x222dc4262BCDbf85190C01c996b4C06a461d2430"
genesisBlockNum:
governanceAddress:
allOf: allOf:
- $ref: '#/components/schemas/EthBlockNum'
- description: Ethereum block number in which the smart contract starts operating.
delayGenesis:
type: integer
description: Time delay between `genesisBlockNum` and the beginning of the first block. Time is measured in Ethereum blocks.
blocksPerSlot:
type: integer
description: Blocks per slot.
initialMinimalBidding:
type: integer
description: Minimum bid when no one has bid yet.
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the governance.
- example: "0x444dc4262BCDbf85190C01c996b4C06a461d2430"
required:
- blocksPerSlot
- initialMinimalBidding
- genesisBlockNum
- tokenHEZ
- hermezRollup
- governanceAddress
additionalProperties: false
withdrawalDelayer: withdrawalDelayer:
type: object type: object
description: Constant configuration of the withdrawal delayer smart contract. description: Constant configuration of the withdrawal delayer smart contract.
@ -2440,6 +2511,21 @@ components:
type: integer type: integer
description: Maximum amount of time in which the contract can be in emergency mode. Time is measured in Ethereum blocks. description: Maximum amount of time in which the contract can be in emergency mode. Time is measured in Ethereum blocks.
example: 2000 example: 2000
hermezRollup:
allOf:
- $ref: '#/components/schemas/EthereumAddress'
- description: Ethereum address of the rollup smart contract.
- example: "0x222dc4262BCDbf85190C01c996b4C06a461d2430"
required:
- maxWithdrawalDelay
- maxEmergencyModeTime
- hermezRollup
additionalProperties: false
required:
- hermez
- auction
- withdrawalDelayer
additionalProperties: false
Error: Error:
type: object type: object
description: Error response. description: Error response.

+ 6
- 6
eth/auction.go

@ -22,18 +22,18 @@ import (
// AuctionConstants are the constants of the Rollup Smart Contract // AuctionConstants are the constants of the Rollup Smart Contract
type AuctionConstants struct { type AuctionConstants struct {
// Blocks per slot // Blocks per slot
BlocksPerSlot uint8
BlocksPerSlot uint8 `json:"blocksPerSlot"`
// Minimum bid when no one has bid yet // Minimum bid when no one has bid yet
InitialMinimalBidding *big.Int
InitialMinimalBidding *big.Int `json:"initialMinimalBidding"`
// First block where the first slot begins // First block where the first slot begins
GenesisBlockNum int64
GenesisBlockNum int64 `json:"genesisBlockNum"`
// ERC777 token with which the bids will be made // ERC777 token with which the bids will be made
TokenHEZ ethCommon.Address
TokenHEZ ethCommon.Address `json:"tokenHEZ"`
// HermezRollup smartcontract address // HermezRollup smartcontract address
HermezRollup ethCommon.Address
HermezRollup ethCommon.Address `json:"hermezRollup"`
// Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee // Hermez Governanze Token smartcontract address who controls some parameters and collects HEZ fee
// Only for test // Only for test
GovernanceAddress ethCommon.Address
GovernanceAddress ethCommon.Address `json:"governanceAddress"`
} }
// SlotState is the state of a slot // SlotState is the state of a slot

+ 9
- 9
eth/rollup.go

@ -101,13 +101,13 @@ var (
// RollupPublicConstants are the constants of the Rollup Smart Contract // RollupPublicConstants are the constants of the Rollup Smart Contract
type RollupPublicConstants struct { type RollupPublicConstants struct {
AbsoluteMaxL1L2BatchTimeout int64
TokenHEZ ethCommon.Address
Verifiers []RollupVerifierStruct
HermezAuctionContract ethCommon.Address
HermezGovernanceDAOAddress ethCommon.Address
SafetyAddress ethCommon.Address
WithdrawDelayerContract ethCommon.Address
AbsoluteMaxL1L2BatchTimeout int64 `json:"absoluteMaxL1L2BatchTimeout"`
TokenHEZ ethCommon.Address `json:"tokenHEZ"`
Verifiers []RollupVerifierStruct `json:"verifiers"`
HermezAuctionContract ethCommon.Address `json:"hermezAuctionContract"`
HermezGovernanceDAOAddress ethCommon.Address `json:"hermezGovernanceDAOAddress"`
SafetyAddress ethCommon.Address `json:"safetyAddress"`
WithdrawDelayerContract ethCommon.Address `json:"withdrawDelayerContract"`
} }
// RollupVariables are the variables of the Rollup Smart Contract // RollupVariables are the variables of the Rollup Smart Contract
@ -133,8 +133,8 @@ func NewQueueStruct() *QueueStruct {
// RollupVerifierStruct is the information about verifiers of the Rollup Smart Contract // RollupVerifierStruct is the information about verifiers of the Rollup Smart Contract
type RollupVerifierStruct struct { type RollupVerifierStruct struct {
MaxTx int64
NLevels int64
MaxTx int64 `json:"maxTx"`
NLevels int64 `json:"nlevels"`
} }
// RollupState represents the state of the Rollup in the Smart Contract // RollupState represents the state of the Rollup in the Smart Contract

+ 3
- 3
eth/wdelayer.go

@ -19,11 +19,11 @@ import (
// WDelayerConstants are the constants of the Rollup Smart Contract // WDelayerConstants are the constants of the Rollup Smart Contract
type WDelayerConstants struct { type WDelayerConstants struct {
// Max Withdrawal Delay // Max Withdrawal Delay
MaxWithdrawalDelay uint64
MaxWithdrawalDelay uint64 `json:"maxWithdrawalDelay"`
// Max Emergency mode time // Max Emergency mode time
MaxEmergencyModeTime uint64
MaxEmergencyModeTime uint64 `json:"maxEmergencyModeTime"`
// HermezRollup smartcontract address // HermezRollup smartcontract address
HermezRollup ethCommon.Address
HermezRollup ethCommon.Address `json:"hermezRollup"`
} }
// DepositState is the state of Deposit // DepositState is the state of Deposit

Loading…
Cancel
Save