Browse Source

fixed pr remarks

refactore/rollupUpdateBuckets
Mikelle 3 years ago
parent
commit
ad4e6e8dcb
8 changed files with 29 additions and 30 deletions
  1. +1
    -1
      api/api_test.go
  2. +0
    -1
      api/config.go
  3. +4
    -4
      api/swagger.yml
  4. +6
    -8
      common/ethrollup.go
  5. +6
    -6
      db/historydb/views.go
  6. +10
    -8
      eth/rollup.go
  7. +1
    -1
      eth/rollup_test.go
  8. +1
    -1
      test/ethclient.go

+ 1
- 1
api/api_test.go

@ -499,7 +499,7 @@ func TestMain(m *testing.M) {
// Slot 7 // Slot 7
nextForgers[6].Coordinator = nonBootForger nextForgers[6].Coordinator = nonBootForger
var buckets [common.RollupConstNumBuckets]common.BucketParams
buckets := make([]common.BucketParams, 5)
for i := range buckets { for i := range buckets {
buckets[i].CeilUSD = big.NewInt(int64(i) * 10) buckets[i].CeilUSD = big.NewInt(int64(i) * 10)
buckets[i].BlockStamp = big.NewInt(int64(i) * 100) buckets[i].BlockStamp = big.NewInt(int64(i) * 100)

+ 0
- 1
api/config.go

@ -41,7 +41,6 @@ func newRollupConstants(publicConstants common.RollupConstants) *rollupConstants
MaxL1UserTx: common.RollupConstMaxL1UserTx, MaxL1UserTx: common.RollupConstMaxL1UserTx,
MaxL1Tx: common.RollupConstMaxL1Tx, MaxL1Tx: common.RollupConstMaxL1Tx,
InputSHAConstantBytes: common.RollupConstInputSHAConstantBytes, InputSHAConstantBytes: common.RollupConstInputSHAConstantBytes,
NumBuckets: common.RollupConstNumBuckets,
MaxWithdrawalDelay: common.RollupConstMaxWithdrawalDelay, MaxWithdrawalDelay: common.RollupConstMaxWithdrawalDelay,
ExchangeMultiplier: common.RollupConstExchangeMultiplier, ExchangeMultiplier: common.RollupConstExchangeMultiplier,
} }

+ 4
- 4
api/swagger.yml

@ -2729,11 +2729,11 @@ components:
properties: properties:
ceilUSD: ceilUSD:
type: string type: string
description: Max USD value
description: Max USD value that bucket holds
example: "1000" example: "1000"
blockStamp: blockStamp:
type: string type: string
description: Block stamp
description: Block number of the last bucket update
example: "1" example: "1"
withdrawals: withdrawals:
type: string type: string
@ -2741,11 +2741,11 @@ components:
example: "4" example: "4"
rateBlocks: rateBlocks:
type: string type: string
description: Rate of blocks
description: rateBlocks every `rateBlocks` blocks add `rateWithdrawals` withdrawal
example: "2" example: "2"
rateWithdrawals: rateWithdrawals:
type: string type: string
description: Rate of withdrawals
description: add `rateWithdrawals` every `rateBlocks`
example: "3" example: "3"
maxWithdrawals: maxWithdrawals:
type: string type: string

+ 6
- 8
common/ethrollup.go

@ -37,8 +37,6 @@ const (
// _L1_USER_TOTALBYTES bytes] l1TxsData + totalL2TxsDataLength + feeIdxCoordinatorLength + // _L1_USER_TOTALBYTES bytes] l1TxsData + totalL2TxsDataLength + feeIdxCoordinatorLength +
// [2 bytes] chainID = 18542 bytes + totalL2TxsDataLength + feeIdxCoordinatorLength // [2 bytes] chainID = 18542 bytes + totalL2TxsDataLength + feeIdxCoordinatorLength
RollupConstInputSHAConstantBytes = 18546 RollupConstInputSHAConstantBytes = 18546
// RollupConstNumBuckets Number of buckets
RollupConstNumBuckets = 5
// RollupConstMaxWithdrawalDelay max withdrawal delay in seconds // RollupConstMaxWithdrawalDelay max withdrawal delay in seconds
RollupConstMaxWithdrawalDelay = 2 * 7 * 24 * 60 * 60 RollupConstMaxWithdrawalDelay = 2 * 7 * 24 * 60 * 60
// RollupConstExchangeMultiplier exchange multiplier // RollupConstExchangeMultiplier exchange multiplier
@ -160,12 +158,12 @@ type TokenExchange struct {
// RollupVariables are the variables of the Rollup Smart Contract // RollupVariables are the variables of the Rollup Smart Contract
//nolint:lll //nolint:lll
type RollupVariables struct { type RollupVariables struct {
EthBlockNum int64 `meddler:"eth_block_num"`
FeeAddToken *big.Int `meddler:"fee_add_token,bigint" validate:"required"`
ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"`
WithdrawalDelay uint64 `meddler:"withdrawal_delay" validate:"required"`
Buckets [RollupConstNumBuckets]BucketParams `meddler:"buckets,json"`
SafeMode bool `meddler:"safe_mode"`
EthBlockNum int64 `meddler:"eth_block_num"`
FeeAddToken *big.Int `meddler:"fee_add_token,bigint" validate:"required"`
ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"`
WithdrawalDelay uint64 `meddler:"withdrawal_delay" validate:"required"`
Buckets []BucketParams `meddler:"buckets,json"`
SafeMode bool `meddler:"safe_mode"`
} }
// Copy returns a deep copy of the Variables // Copy returns a deep copy of the Variables

+ 6
- 6
db/historydb/views.go

@ -364,12 +364,12 @@ type BucketParamsAPI struct {
// RollupVariablesAPI are the variables of the Rollup Smart Contract // RollupVariablesAPI are the variables of the Rollup Smart Contract
type RollupVariablesAPI struct { type RollupVariablesAPI struct {
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
FeeAddToken *apitypes.BigIntStr `json:"feeAddToken" meddler:"fee_add_token" validate:"required"`
ForgeL1L2BatchTimeout int64 `json:"forgeL1L2BatchTimeout" meddler:"forge_l1_timeout" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
Buckets [common.RollupConstNumBuckets]BucketParamsAPI `json:"buckets" meddler:"buckets,json"`
SafeMode bool `json:"safeMode" meddler:"safe_mode"`
EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
FeeAddToken *apitypes.BigIntStr `json:"feeAddToken" meddler:"fee_add_token" validate:"required"`
ForgeL1L2BatchTimeout int64 `json:"forgeL1L2BatchTimeout" meddler:"forge_l1_timeout" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
Buckets []BucketParamsAPI `json:"buckets" meddler:"buckets,json"`
SafeMode bool `json:"safeMode" meddler:"safe_mode"`
} }
// NewRollupVariablesAPI creates a RollupVariablesAPI from common.RollupVariables // NewRollupVariablesAPI creates a RollupVariablesAPI from common.RollupVariables

+ 10
- 8
eth/rollup.go

@ -60,7 +60,7 @@ type RollupEventInitialize struct {
// RollupVariables returns the RollupVariables from the initialize event // RollupVariables returns the RollupVariables from the initialize event
func (ei *RollupEventInitialize) RollupVariables() *common.RollupVariables { func (ei *RollupEventInitialize) RollupVariables() *common.RollupVariables {
var buckets [common.RollupConstNumBuckets]common.BucketParams
buckets := make([]common.BucketParams, 1)
for i := range buckets { for i := range buckets {
buckets[i] = common.BucketParams{ buckets[i] = common.BucketParams{
CeilUSD: big.NewInt(0), CeilUSD: big.NewInt(0),
@ -161,8 +161,7 @@ type rollupEventUpdateBucketsParametersAux struct {
// RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract // RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract
type RollupEventUpdateBucketsParameters struct { type RollupEventUpdateBucketsParameters struct {
// ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
ArrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters
ArrayBuckets []RollupUpdateBucketsParameters
SafeMode bool SafeMode bool
} }
@ -496,8 +495,8 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ babyjub.PublicKeyComp, fro
auth.Value = depositAmount auth.Value = depositAmount
} }
var permit []byte var permit []byte
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, big.NewInt(0).SetUint64(uint64(depositAmountF)),
big.NewInt(0).SetUint64(uint64(amountF)), tokenID, toIdxBig, permit)
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, big.NewInt(int64(depositAmountF)),
big.NewInt(int64(amountF)), tokenID, toIdxBig, permit)
}, },
); err != nil { ); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err)) return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20/ETH: %w", err))
@ -545,7 +544,7 @@ func (c *RollupClient) RollupL1UserTxERC20Permit(fromBJJ babyjub.PublicKeyComp,
signature, _ := c.client.ks.SignHash(*c.client.account, digest) signature, _ := c.client.ks.SignHash(*c.client.account, digest)
permit := createPermit(owner, spender, amount, deadline, digest, signature) permit := createPermit(owner, spender, amount, deadline, digest, signature)
return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig,
big.NewInt(0).SetUint64(uint64(depositAmountF)), big.NewInt(0).SetUint64(uint64(amountF)), tokenID, toIdxBig, permit)
big.NewInt(int64(depositAmountF)), big.NewInt(int64(amountF)), tokenID, toIdxBig, permit)
}, },
); err != nil { ); err != nil {
return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err)) return nil, tracerr.Wrap(fmt.Errorf("Failed add L1 Tx ERC20Permit: %w", err))
@ -607,14 +606,16 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ
// RollupUpdateBucketsParameters is the interface to call the smart contract function // RollupUpdateBucketsParameters is the interface to call the smart contract function
func (c *RollupClient) RollupUpdateBucketsParameters( func (c *RollupClient) RollupUpdateBucketsParameters(
arrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters,
arrayBuckets []RollupUpdateBucketsParameters,
) (tx *types.Transaction, err error) { ) (tx *types.Transaction, err error) {
if tx, err = c.client.CallAuth( if tx, err = c.client.CallAuth(
12500000, //nolint:gomnd 12500000, //nolint:gomnd
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) { func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
params := make([]*big.Int, len(arrayBuckets)) params := make([]*big.Int, len(arrayBuckets))
for i, bucket := range arrayBuckets { for i, bucket := range arrayBuckets {
params[i], err = c.hermez.PackBucket(c.opts, bucket.CeilUSD, bucket.BlockStamp, bucket.Withdrawals, bucket.RateBlocks, bucket.RateWithdrawals, bucket.MaxWithdrawals)
params[i], err = c.hermez.PackBucket(c.opts,
bucket.CeilUSD, bucket.BlockStamp, bucket.Withdrawals,
bucket.RateBlocks, bucket.RateWithdrawals, bucket.MaxWithdrawals)
if err != nil { if err != nil {
return nil, tracerr.Wrap(fmt.Errorf("failed to pack bucket: %w", err)) return nil, tracerr.Wrap(fmt.Errorf("failed to pack bucket: %w", err))
} }
@ -909,6 +910,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64,
if err != nil { if err != nil {
return nil, tracerr.Wrap(err) return nil, tracerr.Wrap(err)
} }
bucketsParameters.ArrayBuckets = make([]RollupUpdateBucketsParameters, len(bucketsParametersAux.ArrayBuckets))
for i, bucket := range bucketsParametersAux.ArrayBuckets { for i, bucket := range bucketsParametersAux.ArrayBuckets {
bucket, err := c.hermez.UnpackBucket(c.opts, bucket) bucket, err := c.hermez.UnpackBucket(c.opts, bucket)
if err != nil { if err != nil {

+ 1
- 1
eth/rollup_test.go

@ -234,7 +234,7 @@ func TestRollupUpdateFeeAddToken(t *testing.T) {
} }
func TestRollupUpdateBucketsParameters(t *testing.T) { func TestRollupUpdateBucketsParameters(t *testing.T) {
var bucketsParameters [common.RollupConstNumBuckets]RollupUpdateBucketsParameters
bucketsParameters := make([]RollupUpdateBucketsParameters, 5)
for i := range bucketsParameters { for i := range bucketsParameters {
bucketsParameters[i].CeilUSD = big.NewInt(int64((i + 1) * 100)) bucketsParameters[i].CeilUSD = big.NewInt(int64((i + 1) * 100))
bucketsParameters[i].BlockStamp = big.NewInt(int64(0)) bucketsParameters[i].BlockStamp = big.NewInt(int64(0))

+ 1
- 1
test/ethclient.go

@ -301,7 +301,7 @@ func NewClientSetupExample() *ClientSetup {
HermezAuctionContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"), HermezAuctionContract: ethCommon.HexToAddress("0x8E442975805fb1908f43050c9C1A522cB0e28D7b"),
WithdrawDelayerContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"), WithdrawDelayerContract: ethCommon.HexToAddress("0x5CB7979cBdbf65719BEE92e4D15b7b7Ed3D79114"),
} }
var buckets [common.RollupConstNumBuckets]common.BucketParams
buckets := make([]common.BucketParams, 1)
for i := range buckets { for i := range buckets {
buckets[i] = common.BucketParams{ buckets[i] = common.BucketParams{
CeilUSD: big.NewInt(0), CeilUSD: big.NewInt(0),

Loading…
Cancel
Save