Compare commits

...

13 Commits

Author SHA1 Message Date
Mikelle
4462fd9c53 updated eth/README.md 2021-03-31 19:51:18 +03:00
Mikelle
49280afc1a fixed rollup_test.go 2021-03-30 21:11:50 +03:00
Mikelle
5d06bfc4e4 fixed synchronizer_test.go 2021-03-25 19:44:41 +03:00
Mikelle
bc9d7fdc90 updated RollupVariables init with empty buckets 2021-03-25 19:31:26 +03:00
Mikelle
dde99d6178 fixed TestNodeInfo test 2021-03-24 20:13:26 +03:00
Mikelle
2841b4e22c fixed struct in historydb_test.go 2021-03-24 19:20:10 +03:00
Mikelle
ad4e6e8dcb fixed pr remarks 2021-03-24 19:13:54 +03:00
Mikelle
aa1f0a2618 fixed rollup event parsing 2021-03-23 10:54:14 +03:00
Mikelle
0f4be6a946 updated rollup according new contract api 2021-03-19 16:02:26 +03:00
Mikelle
602e1e7634 Merge remote-tracking branch 'origin/feature/update-smart-contracts' into refactore/rollupUpdateBuckets
# Conflicts:
#	eth/contracts/hermez/Hermez.go
2021-03-19 14:44:16 +03:00
Oleksandr Brezhniev
6aac050858 Update smart contract ABIs 2021-03-19 13:37:15 +02:00
Mikelle
cd7cdef339 fixed blockstamp naming in BucketParamsAPI 2021-03-19 12:56:57 +03:00
Mikelle
379ca78b4e updated rollup buckets to the current state 2021-03-19 12:36:34 +03:00
15 changed files with 563 additions and 200 deletions

View File

@@ -499,12 +499,14 @@ 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].Withdrawals = big.NewInt(int64(i) * 100) buckets[i].BlockStamp = big.NewInt(int64(i) * 100)
buckets[i].BlockWithdrawalRate = big.NewInt(int64(i) * 1000) buckets[i].Withdrawals = big.NewInt(int64(i) * 1000)
buckets[i].MaxWithdrawals = big.NewInt(int64(i) * 10000) buckets[i].RateBlocks = big.NewInt(int64(i) * 10000)
buckets[i].RateWithdrawals = big.NewInt(int64(i) * 100000)
buckets[i].MaxWithdrawals = big.NewInt(int64(i) * 1000000)
} }
// Generate SC vars and add them to HistoryDB (if needed) // Generate SC vars and add them to HistoryDB (if needed)

View File

@@ -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,
} }

View File

@@ -43,7 +43,9 @@ func assertEqualRollupVariables(t *testing.T, rollupVariables common.RollupVaria
assert.Equal(t, rollupVariables.SafeMode, apiVariables.SafeMode) assert.Equal(t, rollupVariables.SafeMode, apiVariables.SafeMode)
if checkBuckets { if checkBuckets {
for i, bucket := range rollupVariables.Buckets { for i, bucket := range rollupVariables.Buckets {
assert.Equal(t, apitypes.NewBigIntStr(bucket.BlockWithdrawalRate), apiVariables.Buckets[i].BlockWithdrawalRate) assert.Equal(t, apitypes.NewBigIntStr(bucket.BlockStamp), apiVariables.Buckets[i].BlockStamp)
assert.Equal(t, apitypes.NewBigIntStr(bucket.RateBlocks), apiVariables.Buckets[i].RateBlocks)
assert.Equal(t, apitypes.NewBigIntStr(bucket.RateWithdrawals), apiVariables.Buckets[i].RateWithdrawals)
assert.Equal(t, apitypes.NewBigIntStr(bucket.CeilUSD), apiVariables.Buckets[i].CeilUSD) assert.Equal(t, apitypes.NewBigIntStr(bucket.CeilUSD), apiVariables.Buckets[i].CeilUSD)
assert.Equal(t, apitypes.NewBigIntStr(bucket.MaxWithdrawals), apiVariables.Buckets[i].MaxWithdrawals) assert.Equal(t, apitypes.NewBigIntStr(bucket.MaxWithdrawals), apiVariables.Buckets[i].MaxWithdrawals)
assert.Equal(t, apitypes.NewBigIntStr(bucket.Withdrawals), apiVariables.Buckets[i].Withdrawals) assert.Equal(t, apitypes.NewBigIntStr(bucket.Withdrawals), apiVariables.Buckets[i].Withdrawals)

View File

@@ -2729,16 +2729,24 @@ 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:
type: string
description: Block number of the last bucket update
example: "1"
withdrawals: withdrawals:
type: string type: string
description: Available withdrawals of the bucket description: Available withdrawals of the bucket
example: "4" example: "4"
blockWithdrawalRate: rateBlocks:
type: string type: string
description: Every `blockWithdrawalRate` blocks add 1 withdrawal description: rateBlocks every `rateBlocks` blocks add `rateWithdrawals` withdrawal
example: "8" example: "2"
rateWithdrawals:
type: string
description: add `rateWithdrawals` every `rateBlocks`
example: "3"
maxWithdrawals: maxWithdrawals:
type: string type: string
description: Max withdrawals the bucket can hold description: Max withdrawals the bucket can hold
@@ -2746,8 +2754,10 @@ components:
additionalProperties: false additionalProperties: false
required: required:
- ceilUSD - ceilUSD
- blockStamp
- withdrawals - withdrawals
- blockWithdrawalRate - rateBlocks
- rateWithdrawals
- maxWithdrawals - maxWithdrawals
additionalProperties: false additionalProperties: false
required: required:

View File

@@ -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
@@ -132,10 +130,12 @@ func (c *RollupConstants) FindVerifierIdx(MaxTx, NLevels int64) (int, error) {
// BucketParams are the parameter variables of each Bucket of Rollup Smart // BucketParams are the parameter variables of each Bucket of Rollup Smart
// Contract // Contract
type BucketParams struct { type BucketParams struct {
CeilUSD *big.Int CeilUSD *big.Int
Withdrawals *big.Int BlockStamp *big.Int
BlockWithdrawalRate *big.Int Withdrawals *big.Int
MaxWithdrawals *big.Int RateBlocks *big.Int
RateWithdrawals *big.Int
MaxWithdrawals *big.Int
} }
// BucketUpdate are the bucket updates (tracking the withdrawals value changes) // BucketUpdate are the bucket updates (tracking the withdrawals value changes)
@@ -158,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"` EthBlockNum int64 `meddler:"eth_block_num"`
FeeAddToken *big.Int `meddler:"fee_add_token,bigint" validate:"required"` FeeAddToken *big.Int `meddler:"fee_add_token,bigint" validate:"required"`
ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"` ForgeL1L2BatchTimeout int64 `meddler:"forge_l1_timeout" validate:"required"`
WithdrawalDelay uint64 `meddler:"withdrawal_delay" validate:"required"` WithdrawalDelay uint64 `meddler:"withdrawal_delay" validate:"required"`
Buckets [RollupConstNumBuckets]BucketParams `meddler:"buckets,json"` Buckets []BucketParams `meddler:"buckets,json"`
SafeMode bool `meddler:"safe_mode"` SafeMode bool `meddler:"safe_mode"`
} }
// Copy returns a deep copy of the Variables // Copy returns a deep copy of the Variables

View File

@@ -738,7 +738,7 @@ func exampleInitSCVars() (*common.RollupVariables, *common.AuctionVariables, *co
big.NewInt(10), big.NewInt(10),
12, 12,
13, 13,
[5]common.BucketParams{}, []common.BucketParams{},
false, false,
} }
//nolint:govet //nolint:govet

View File

@@ -354,38 +354,43 @@ type BucketUpdateAPI struct {
// BucketParamsAPI are the parameter variables of each Bucket of Rollup Smart // BucketParamsAPI are the parameter variables of each Bucket of Rollup Smart
// Contract // Contract
type BucketParamsAPI struct { type BucketParamsAPI struct {
CeilUSD *apitypes.BigIntStr `json:"ceilUSD"` CeilUSD *apitypes.BigIntStr `json:"ceilUSD"`
Withdrawals *apitypes.BigIntStr `json:"withdrawals"` BlockStamp *apitypes.BigIntStr `json:"blockStamp"`
BlockWithdrawalRate *apitypes.BigIntStr `json:"blockWithdrawalRate"` Withdrawals *apitypes.BigIntStr `json:"withdrawals"`
MaxWithdrawals *apitypes.BigIntStr `json:"maxWithdrawals"` RateBlocks *apitypes.BigIntStr `json:"rateBlocks"`
RateWithdrawals *apitypes.BigIntStr `json:"rateWithdrawals"`
MaxWithdrawals *apitypes.BigIntStr `json:"maxWithdrawals"`
} }
// 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"` EthBlockNum int64 `json:"ethereumBlockNum" meddler:"eth_block_num"`
FeeAddToken *apitypes.BigIntStr `json:"feeAddToken" meddler:"fee_add_token" validate:"required"` FeeAddToken *apitypes.BigIntStr `json:"feeAddToken" meddler:"fee_add_token" validate:"required"`
ForgeL1L2BatchTimeout int64 `json:"forgeL1L2BatchTimeout" meddler:"forge_l1_timeout" validate:"required"` ForgeL1L2BatchTimeout int64 `json:"forgeL1L2BatchTimeout" meddler:"forge_l1_timeout" validate:"required"`
WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"` WithdrawalDelay uint64 `json:"withdrawalDelay" meddler:"withdrawal_delay" validate:"required"`
Buckets [common.RollupConstNumBuckets]BucketParamsAPI `json:"buckets" meddler:"buckets,json"` Buckets []BucketParamsAPI `json:"buckets" meddler:"buckets,json"`
SafeMode bool `json:"safeMode" meddler:"safe_mode"` SafeMode bool `json:"safeMode" meddler:"safe_mode"`
} }
// NewRollupVariablesAPI creates a RollupVariablesAPI from common.RollupVariables // NewRollupVariablesAPI creates a RollupVariablesAPI from common.RollupVariables
func NewRollupVariablesAPI(rollupVariables *common.RollupVariables) *RollupVariablesAPI { func NewRollupVariablesAPI(rollupVariables *common.RollupVariables) *RollupVariablesAPI {
buckets := make([]BucketParamsAPI, len(rollupVariables.Buckets))
rollupVars := RollupVariablesAPI{ rollupVars := RollupVariablesAPI{
EthBlockNum: rollupVariables.EthBlockNum, EthBlockNum: rollupVariables.EthBlockNum,
FeeAddToken: apitypes.NewBigIntStr(rollupVariables.FeeAddToken), FeeAddToken: apitypes.NewBigIntStr(rollupVariables.FeeAddToken),
ForgeL1L2BatchTimeout: rollupVariables.ForgeL1L2BatchTimeout, ForgeL1L2BatchTimeout: rollupVariables.ForgeL1L2BatchTimeout,
WithdrawalDelay: rollupVariables.WithdrawalDelay, WithdrawalDelay: rollupVariables.WithdrawalDelay,
SafeMode: rollupVariables.SafeMode, SafeMode: rollupVariables.SafeMode,
Buckets: buckets,
} }
for i, bucket := range rollupVariables.Buckets { for i, bucket := range rollupVariables.Buckets {
rollupVars.Buckets[i] = BucketParamsAPI{ rollupVars.Buckets[i] = BucketParamsAPI{
CeilUSD: apitypes.NewBigIntStr(bucket.CeilUSD), CeilUSD: apitypes.NewBigIntStr(bucket.CeilUSD),
Withdrawals: apitypes.NewBigIntStr(bucket.Withdrawals), BlockStamp: apitypes.NewBigIntStr(bucket.BlockStamp),
BlockWithdrawalRate: apitypes.NewBigIntStr(bucket.BlockWithdrawalRate), Withdrawals: apitypes.NewBigIntStr(bucket.Withdrawals),
MaxWithdrawals: apitypes.NewBigIntStr(bucket.MaxWithdrawals), RateBlocks: apitypes.NewBigIntStr(bucket.RateBlocks),
RateWithdrawals: apitypes.NewBigIntStr(bucket.RateWithdrawals),
MaxWithdrawals: apitypes.NewBigIntStr(bucket.MaxWithdrawals),
} }
} }
return &rollupVars return &rollupVars

View File

@@ -8,7 +8,7 @@ The first step is to clone the github repository where the contracts are located
While the prepared deployment is not found to master, branch in repository must be changed: While the prepared deployment is not found to master, branch in repository must be changed:
`git checkout feature/newDeploymentScript-eth-edu` (tested with commit `e6c5b7db8da2de1b9cc55e281c8d1dfa524b06f0`) `git checkout feature/newDeploymentScript-eth-mik` (tested with commit `0eccd237dda102a4ad788a6e11f98361d39d0d9c`)
Now, install the dependencies: Now, install the dependencies:

View File

@@ -309,9 +309,12 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) Coordinators(opts *bi
Forger common.Address Forger common.Address
CoordinatorURL string CoordinatorURL string
}) })
if err != nil {
return *outstruct, err
}
outstruct.Forger = out[0].(common.Address) outstruct.Forger = *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
outstruct.CoordinatorURL = out[1].(string) outstruct.CoordinatorURL = *abi.ConvertType(out[1], new(string)).(*string)
return *outstruct, err return *outstruct, err
@@ -884,12 +887,15 @@ func (_HermezAuctionProtocol *HermezAuctionProtocolCaller) Slots(opts *bind.Call
BidAmount *big.Int BidAmount *big.Int
ClosedMinBid *big.Int ClosedMinBid *big.Int
}) })
if err != nil {
return *outstruct, err
}
outstruct.Bidder = out[0].(common.Address) outstruct.Bidder = *abi.ConvertType(out[0], new(common.Address)).(*common.Address)
outstruct.Fulfilled = out[1].(bool) outstruct.Fulfilled = *abi.ConvertType(out[1], new(bool)).(*bool)
outstruct.ForgerCommitment = out[2].(bool) outstruct.ForgerCommitment = *abi.ConvertType(out[2], new(bool)).(*bool)
outstruct.BidAmount = out[3].(*big.Int) outstruct.BidAmount = *abi.ConvertType(out[3], new(*big.Int)).(**big.Int)
outstruct.ClosedMinBid = out[4].(*big.Int) outstruct.ClosedMinBid = *abi.ConvertType(out[4], new(*big.Int)).(**big.Int)
return *outstruct, err return *outstruct, err

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"math/big" "math/big"
"strconv"
"strings" "strings"
"github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum"
@@ -61,21 +60,12 @@ 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
for i := range buckets {
buckets[i] = common.BucketParams{
CeilUSD: big.NewInt(0),
Withdrawals: big.NewInt(0),
BlockWithdrawalRate: big.NewInt(0),
MaxWithdrawals: big.NewInt(0),
}
}
return &common.RollupVariables{ return &common.RollupVariables{
EthBlockNum: 0, EthBlockNum: 0,
FeeAddToken: ei.FeeAddToken, FeeAddToken: ei.FeeAddToken,
ForgeL1L2BatchTimeout: int64(ei.ForgeL1L2BatchTimeout), ForgeL1L2BatchTimeout: int64(ei.ForgeL1L2BatchTimeout),
WithdrawalDelay: ei.WithdrawalDelay, WithdrawalDelay: ei.WithdrawalDelay,
Buckets: buckets, Buckets: []common.BucketParams{},
SafeMode: false, SafeMode: false,
} }
} }
@@ -146,20 +136,21 @@ type RollupEventUpdateWithdrawalDelay struct {
// RollupUpdateBucketsParameters are the bucket parameters used in an update // RollupUpdateBucketsParameters are the bucket parameters used in an update
type RollupUpdateBucketsParameters struct { type RollupUpdateBucketsParameters struct {
CeilUSD *big.Int CeilUSD *big.Int
Withdrawals *big.Int BlockStamp *big.Int
BlockWithdrawalRate *big.Int Withdrawals *big.Int
MaxWithdrawals *big.Int RateBlocks *big.Int
RateWithdrawals *big.Int
MaxWithdrawals *big.Int
} }
type rollupEventUpdateBucketsParametersAux struct { type rollupEventUpdateBucketsParametersAux struct {
ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int ArrayBuckets []*big.Int
} }
// 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 []RollupUpdateBucketsParameters
ArrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters
SafeMode bool SafeMode bool
} }
@@ -493,8 +484,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, uint16(depositAmountF), return c.hermez.AddL1Transaction(auth, babyPubKey, fromIdxBig, big.NewInt(int64(depositAmountF)),
uint16(amountF), tokenID, toIdxBig, permit) 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))
@@ -542,7 +533,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,
uint16(depositAmountF), uint16(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))
@@ -604,18 +595,20 @@ 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) {
params := [common.RollupConstNumBuckets][4]*big.Int{}
for i, bucket := range arrayBuckets {
params[i][0] = bucket.CeilUSD
params[i][1] = bucket.Withdrawals
params[i][2] = bucket.BlockWithdrawalRate
params[i][3] = bucket.MaxWithdrawals
}
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))
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)
if err != nil {
return nil, tracerr.Wrap(fmt.Errorf("failed to pack bucket: %w", err))
}
}
return c.hermez.UpdateBucketsParameters(auth, params) return c.hermez.UpdateBucketsParameters(auth, params)
}, },
); err != nil { ); err != nil {
@@ -739,7 +732,7 @@ var (
logHermezUpdateWithdrawalDelay = crypto.Keccak256Hash([]byte( logHermezUpdateWithdrawalDelay = crypto.Keccak256Hash([]byte(
"UpdateWithdrawalDelay(uint64)")) "UpdateWithdrawalDelay(uint64)"))
logHermezUpdateBucketsParameters = crypto.Keccak256Hash([]byte( logHermezUpdateBucketsParameters = crypto.Keccak256Hash([]byte(
"UpdateBucketsParameters(uint256[4][" + strconv.Itoa(common.RollupConstNumBuckets) + "])")) "UpdateBucketsParameters(uint256[])"))
logHermezUpdateTokenExchange = crypto.Keccak256Hash([]byte( logHermezUpdateTokenExchange = crypto.Keccak256Hash([]byte(
"UpdateTokenExchange(address[],uint64[])")) "UpdateTokenExchange(address[],uint64[])"))
logHermezSafeMode = crypto.Keccak256Hash([]byte( logHermezSafeMode = crypto.Keccak256Hash([]byte(
@@ -906,11 +899,18 @@ 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 {
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket[0] bucket, err := c.hermez.UnpackBucket(c.opts, bucket)
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[1] if err != nil {
bucketsParameters.ArrayBuckets[i].BlockWithdrawalRate = bucket[2] return nil, tracerr.Wrap(err)
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[3] }
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket.CeilUSD
bucketsParameters.ArrayBuckets[i].BlockStamp = bucket.BlockStamp
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket.Withdrawals
bucketsParameters.ArrayBuckets[i].RateBlocks = bucket.RateBlocks
bucketsParameters.ArrayBuckets[i].RateWithdrawals = bucket.RateWithdrawals
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket.MaxWithdrawals
} }
rollupEvents.UpdateBucketsParameters = rollupEvents.UpdateBucketsParameters =
append(rollupEvents.UpdateBucketsParameters, bucketsParameters) append(rollupEvents.UpdateBucketsParameters, bucketsParameters)
@@ -932,8 +932,10 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64,
} }
for i := range bucketsParameters.ArrayBuckets { for i := range bucketsParameters.ArrayBuckets {
bucketsParameters.ArrayBuckets[i].CeilUSD = big.NewInt(0) bucketsParameters.ArrayBuckets[i].CeilUSD = big.NewInt(0)
bucketsParameters.ArrayBuckets[i].BlockStamp = big.NewInt(0)
bucketsParameters.ArrayBuckets[i].Withdrawals = big.NewInt(0) bucketsParameters.ArrayBuckets[i].Withdrawals = big.NewInt(0)
bucketsParameters.ArrayBuckets[i].BlockWithdrawalRate = big.NewInt(0) bucketsParameters.ArrayBuckets[i].RateBlocks = big.NewInt(0)
bucketsParameters.ArrayBuckets[i].RateWithdrawals = big.NewInt(0)
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = big.NewInt(0) bucketsParameters.ArrayBuckets[i].MaxWithdrawals = big.NewInt(0)
} }
rollupEvents.UpdateBucketsParameters = append(rollupEvents.UpdateBucketsParameters, rollupEvents.UpdateBucketsParameters = append(rollupEvents.UpdateBucketsParameters,

View File

@@ -234,12 +234,15 @@ func TestRollupUpdateFeeAddToken(t *testing.T) {
} }
func TestRollupUpdateBucketsParameters(t *testing.T) { func TestRollupUpdateBucketsParameters(t *testing.T) {
var bucketsParameters [common.RollupConstNumBuckets]RollupUpdateBucketsParameters bucketsParameters := make([]RollupUpdateBucketsParameters, 5)
ceilUSD, _ := new(big.Int).SetString("10000000", 10)
for i := range bucketsParameters { for i := range bucketsParameters {
bucketsParameters[i].CeilUSD = big.NewInt(int64((i + 1) * 100)) bucketsParameters[i].CeilUSD = big.NewInt(0).Mul(ceilUSD, big.NewInt(int64(i+1)))
bucketsParameters[i].BlockStamp = big.NewInt(int64(0))
bucketsParameters[i].Withdrawals = big.NewInt(int64(i + 1)) bucketsParameters[i].Withdrawals = big.NewInt(int64(i + 1))
bucketsParameters[i].BlockWithdrawalRate = big.NewInt(int64(i+1) * 100) bucketsParameters[i].RateBlocks = big.NewInt(int64(i+1) * 4)
bucketsParameters[i].MaxWithdrawals = big.NewInt(int64(100000000000)) bucketsParameters[i].RateWithdrawals = big.NewInt(int64(3))
bucketsParameters[i].MaxWithdrawals = big.NewInt(int64(1215752192))
} }
_, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters) _, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters)
require.NoError(t, err) require.NoError(t, err)
@@ -248,7 +251,14 @@ func TestRollupUpdateBucketsParameters(t *testing.T) {
blockStampBucket = currentBlockNum blockStampBucket = currentBlockNum
rollupEvents, err := rollupClient.RollupEventsByBlock(currentBlockNum, nil) rollupEvents, err := rollupClient.RollupEventsByBlock(currentBlockNum, nil)
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, bucketsParameters, rollupEvents.UpdateBucketsParameters[0].ArrayBuckets) for i := range bucketsParameters {
assert.Equal(t, 0, bucketsParameters[i].CeilUSD.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].CeilUSD))
assert.Equal(t, 0, bucketsParameters[i].BlockStamp.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].BlockStamp))
assert.Equal(t, 0, bucketsParameters[i].Withdrawals.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].Withdrawals))
assert.Equal(t, 0, bucketsParameters[i].RateBlocks.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].RateBlocks))
assert.Equal(t, 0, bucketsParameters[i].RateWithdrawals.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].RateWithdrawals))
assert.Equal(t, 0, bucketsParameters[i].MaxWithdrawals.Cmp(rollupEvents.UpdateBucketsParameters[0].ArrayBuckets[i].MaxWithdrawals))
}
} }
func TestRollupUpdateWithdrawalDelay(t *testing.T) { func TestRollupUpdateWithdrawalDelay(t *testing.T) {
@@ -1016,9 +1026,9 @@ func TestRollupWithdrawMerkleProof(t *testing.T) {
// Bucket 1 // Bucket 1
// Bucket[0].withdrawals = 1, Bucket[1].withdrawals = 2, ... // Bucket[0].withdrawals = 1, Bucket[1].withdrawals = 2, ...
// Bucket[1].withdrawals - 1 = 1 // Bucket[1].withdrawals - 1 = 1
assert.Equal(t, 1, rollupEvents.UpdateBucketWithdraw[0].NumBucket) assert.Equal(t, 0, rollupEvents.UpdateBucketWithdraw[0].NumBucket)
assert.Equal(t, blockStampBucket, rollupEvents.UpdateBucketWithdraw[0].BlockStamp) assert.Equal(t, int64(442), rollupEvents.UpdateBucketWithdraw[0].BlockStamp)
assert.Equal(t, big.NewInt(1), rollupEvents.UpdateBucketWithdraw[0].Withdrawals) assert.Equal(t, big.NewInt(15), rollupEvents.UpdateBucketWithdraw[0].Withdrawals)
} }
func TestRollupSafeMode(t *testing.T) { func TestRollupSafeMode(t *testing.T) {

View File

@@ -1125,10 +1125,12 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
for _, evt := range rollupEvents.UpdateBucketsParameters { for _, evt := range rollupEvents.UpdateBucketsParameters {
for i, bucket := range evt.ArrayBuckets { for i, bucket := range evt.ArrayBuckets {
s.vars.Rollup.Buckets[i] = common.BucketParams{ s.vars.Rollup.Buckets[i] = common.BucketParams{
CeilUSD: bucket.CeilUSD, CeilUSD: bucket.CeilUSD,
Withdrawals: bucket.Withdrawals, BlockStamp: bucket.BlockStamp,
BlockWithdrawalRate: bucket.BlockWithdrawalRate, Withdrawals: bucket.Withdrawals,
MaxWithdrawals: bucket.MaxWithdrawals, RateBlocks: bucket.RateBlocks,
RateWithdrawals: bucket.RateWithdrawals,
MaxWithdrawals: bucket.MaxWithdrawals,
} }
} }
s.vars.Rollup.SafeMode = evt.SafeMode s.vars.Rollup.SafeMode = evt.SafeMode

View File

@@ -301,20 +301,11 @@ 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
for i := range buckets {
buckets[i] = common.BucketParams{
CeilUSD: big.NewInt(0),
Withdrawals: big.NewInt(0),
BlockWithdrawalRate: big.NewInt(0),
MaxWithdrawals: big.NewInt(0),
}
}
rollupVariables := &common.RollupVariables{ rollupVariables := &common.RollupVariables{
FeeAddToken: big.NewInt(11), FeeAddToken: big.NewInt(11),
ForgeL1L2BatchTimeout: 10, ForgeL1L2BatchTimeout: 10,
WithdrawalDelay: 80, WithdrawalDelay: 80,
Buckets: buckets, Buckets: []common.BucketParams{},
} }
auctionConstants := &common.AuctionConstants{ auctionConstants := &common.AuctionConstants{
BlocksPerSlot: 40, BlocksPerSlot: 40,