updated rollup buckets to the current state

This commit is contained in:
Mikelle
2021-03-19 12:36:34 +03:00
parent 4ebe285912
commit 379ca78b4e
10 changed files with 116 additions and 75 deletions

View File

@@ -502,9 +502,11 @@ func TestMain(m *testing.M) {
var buckets [common.RollupConstNumBuckets]common.BucketParams var buckets [common.RollupConstNumBuckets]common.BucketParams
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

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

@@ -2731,14 +2731,22 @@ components:
type: string type: string
description: Max USD value description: Max USD value
example: "1000" example: "1000"
blockStamp:
type: string
description: Block stamp
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: Rate of blocks
example: "8" example: "2"
rateWithdrawals:
type: string
description: Rate of withdrawals
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

@@ -133,8 +133,10 @@ func (c *RollupConstants) FindVerifierIdx(MaxTx, NLevels int64) (int, error) {
// Contract // Contract
type BucketParams struct { type BucketParams struct {
CeilUSD *big.Int CeilUSD *big.Int
BlockStamp *big.Int
Withdrawals *big.Int Withdrawals *big.Int
BlockWithdrawalRate *big.Int RateBlocks *big.Int
RateWithdrawals *big.Int
MaxWithdrawals *big.Int MaxWithdrawals *big.Int
} }

View File

@@ -355,8 +355,10 @@ type BucketUpdateAPI struct {
// Contract // Contract
type BucketParamsAPI struct { type BucketParamsAPI struct {
CeilUSD *apitypes.BigIntStr `json:"ceilUSD"` CeilUSD *apitypes.BigIntStr `json:"ceilUSD"`
BlockStamp *apitypes.BigIntStr `json:"blockstamp"`
Withdrawals *apitypes.BigIntStr `json:"withdrawals"` Withdrawals *apitypes.BigIntStr `json:"withdrawals"`
BlockWithdrawalRate *apitypes.BigIntStr `json:"blockWithdrawalRate"` RateBlocks *apitypes.BigIntStr `json:"rateBlocks"`
RateWithdrawals *apitypes.BigIntStr `json:"rateWithdrawals"`
MaxWithdrawals *apitypes.BigIntStr `json:"maxWithdrawals"` MaxWithdrawals *apitypes.BigIntStr `json:"maxWithdrawals"`
} }
@@ -383,8 +385,10 @@ func NewRollupVariablesAPI(rollupVariables *common.RollupVariables) *RollupVaria
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),
BlockStamp: apitypes.NewBigIntStr(bucket.BlockStamp),
Withdrawals: apitypes.NewBigIntStr(bucket.Withdrawals), Withdrawals: apitypes.NewBigIntStr(bucket.Withdrawals),
BlockWithdrawalRate: apitypes.NewBigIntStr(bucket.BlockWithdrawalRate), RateBlocks: apitypes.NewBigIntStr(bucket.RateBlocks),
RateWithdrawals: apitypes.NewBigIntStr(bucket.RateWithdrawals),
MaxWithdrawals: apitypes.NewBigIntStr(bucket.MaxWithdrawals), MaxWithdrawals: apitypes.NewBigIntStr(bucket.MaxWithdrawals),
} }
} }

File diff suppressed because one or more lines are too long

View File

@@ -65,8 +65,10 @@ func (ei *RollupEventInitialize) RollupVariables() *common.RollupVariables {
for i := range buckets { for i := range buckets {
buckets[i] = common.BucketParams{ buckets[i] = common.BucketParams{
CeilUSD: big.NewInt(0), CeilUSD: big.NewInt(0),
BlockStamp: big.NewInt(0),
Withdrawals: big.NewInt(0), Withdrawals: big.NewInt(0),
BlockWithdrawalRate: big.NewInt(0), RateBlocks: big.NewInt(0),
RateWithdrawals: big.NewInt(0),
MaxWithdrawals: big.NewInt(0), MaxWithdrawals: big.NewInt(0),
} }
} }
@@ -147,13 +149,15 @@ 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
BlockStamp *big.Int
Withdrawals *big.Int Withdrawals *big.Int
BlockWithdrawalRate *big.Int RateBlocks *big.Int
RateWithdrawals *big.Int
MaxWithdrawals *big.Int MaxWithdrawals *big.Int
} }
type rollupEventUpdateBucketsParametersAux struct { type rollupEventUpdateBucketsParametersAux struct {
ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int ArrayBuckets [common.RollupConstNumBuckets][6]*big.Int
} }
// RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract // RollupEventUpdateBucketsParameters is an event of the Rollup Smart Contract
@@ -606,12 +610,14 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *typ
func (c *RollupClient) RollupUpdateBucketsParameters( func (c *RollupClient) RollupUpdateBucketsParameters(
arrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters, arrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters,
) (tx *types.Transaction, err error) { ) (tx *types.Transaction, err error) {
params := [common.RollupConstNumBuckets][4]*big.Int{} params := [common.RollupConstNumBuckets][6]*big.Int{}
for i, bucket := range arrayBuckets { for i, bucket := range arrayBuckets {
params[i][0] = bucket.CeilUSD params[i][0] = bucket.CeilUSD
params[i][1] = bucket.Withdrawals params[i][1] = bucket.BlockStamp
params[i][2] = bucket.BlockWithdrawalRate params[i][2] = bucket.Withdrawals
params[i][3] = bucket.MaxWithdrawals params[i][3] = bucket.RateBlocks
params[i][4] = bucket.RateWithdrawals
params[i][5] = bucket.MaxWithdrawals
} }
if tx, err = c.client.CallAuth( if tx, err = c.client.CallAuth(
12500000, //nolint:gomnd 12500000, //nolint:gomnd
@@ -908,9 +914,11 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64,
} }
for i, bucket := range bucketsParametersAux.ArrayBuckets { for i, bucket := range bucketsParametersAux.ArrayBuckets {
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket[0] bucketsParameters.ArrayBuckets[i].CeilUSD = bucket[0]
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[1] bucketsParameters.ArrayBuckets[i].BlockStamp = bucket[1]
bucketsParameters.ArrayBuckets[i].BlockWithdrawalRate = bucket[2] bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[2]
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[3] bucketsParameters.ArrayBuckets[i].RateBlocks = bucket[3]
bucketsParameters.ArrayBuckets[i].RateWithdrawals = bucket[4]
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[5]
} }
rollupEvents.UpdateBucketsParameters = rollupEvents.UpdateBucketsParameters =
append(rollupEvents.UpdateBucketsParameters, bucketsParameters) append(rollupEvents.UpdateBucketsParameters, bucketsParameters)
@@ -932,8 +940,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

@@ -237,8 +237,10 @@ func TestRollupUpdateBucketsParameters(t *testing.T) {
var bucketsParameters [common.RollupConstNumBuckets]RollupUpdateBucketsParameters var bucketsParameters [common.RollupConstNumBuckets]RollupUpdateBucketsParameters
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].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].RateWithdrawals = big.NewInt(int64(3))
bucketsParameters[i].MaxWithdrawals = big.NewInt(int64(100000000000)) bucketsParameters[i].MaxWithdrawals = big.NewInt(int64(100000000000))
} }
_, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters) _, err := rollupClient.RollupUpdateBucketsParameters(bucketsParameters)

View File

@@ -1126,8 +1126,10 @@ func (s *Synchronizer) rollupSync(ethBlock *common.Block) (*common.RollupData, e
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,
BlockStamp: bucket.BlockStamp,
Withdrawals: bucket.Withdrawals, Withdrawals: bucket.Withdrawals,
BlockWithdrawalRate: bucket.BlockWithdrawalRate, RateBlocks: bucket.RateBlocks,
RateWithdrawals: bucket.RateWithdrawals,
MaxWithdrawals: bucket.MaxWithdrawals, MaxWithdrawals: bucket.MaxWithdrawals,
} }
} }

View File

@@ -305,8 +305,10 @@ func NewClientSetupExample() *ClientSetup {
for i := range buckets { for i := range buckets {
buckets[i] = common.BucketParams{ buckets[i] = common.BucketParams{
CeilUSD: big.NewInt(0), CeilUSD: big.NewInt(0),
BlockStamp: big.NewInt(0),
Withdrawals: big.NewInt(0), Withdrawals: big.NewInt(0),
BlockWithdrawalRate: big.NewInt(0), RateBlocks: big.NewInt(0),
RateWithdrawals: big.NewInt(0),
MaxWithdrawals: big.NewInt(0), MaxWithdrawals: big.NewInt(0),
} }
} }