Browse Source

updated rollup buckets to the current state

refactore/rollupUpdateBuckets
Mikelle 3 years ago
parent
commit
379ca78b4e
10 changed files with 116 additions and 75 deletions
  1. +5
    -3
      api/api_test.go
  2. +3
    -1
      api/state_test.go
  3. +14
    -4
      api/swagger.yml
  4. +6
    -4
      common/ethrollup.go
  5. +12
    -8
      db/historydb/views.go
  6. +34
    -29
      eth/contracts/hermez/Hermez.go
  7. +27
    -17
      eth/rollup.go
  8. +3
    -1
      eth/rollup_test.go
  9. +6
    -4
      synchronizer/synchronizer.go
  10. +6
    -4
      test/ethclient.go

+ 5
- 3
api/api_test.go

@ -502,9 +502,11 @@ func TestMain(m *testing.M) {
var buckets [common.RollupConstNumBuckets]common.BucketParams
for i := range buckets {
buckets[i].CeilUSD = big.NewInt(int64(i) * 10)
buckets[i].Withdrawals = big.NewInt(int64(i) * 100)
buckets[i].BlockWithdrawalRate = big.NewInt(int64(i) * 1000)
buckets[i].MaxWithdrawals = big.NewInt(int64(i) * 10000)
buckets[i].BlockStamp = big.NewInt(int64(i) * 100)
buckets[i].Withdrawals = big.NewInt(int64(i) * 1000)
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)

+ 3
- 1
api/state_test.go

@ -43,7 +43,9 @@ func assertEqualRollupVariables(t *testing.T, rollupVariables common.RollupVaria
assert.Equal(t, rollupVariables.SafeMode, apiVariables.SafeMode)
if checkBuckets {
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.MaxWithdrawals), apiVariables.Buckets[i].MaxWithdrawals)
assert.Equal(t, apitypes.NewBigIntStr(bucket.Withdrawals), apiVariables.Buckets[i].Withdrawals)

+ 14
- 4
api/swagger.yml

@ -2731,14 +2731,22 @@ components:
type: string
description: Max USD value
example: "1000"
blockStamp:
type: string
description: Block stamp
example: "1"
withdrawals:
type: string
description: Available withdrawals of the bucket
example: "4"
blockWithdrawalRate:
rateBlocks:
type: string
description: Rate of blocks
example: "2"
rateWithdrawals:
type: string
description: Every `blockWithdrawalRate` blocks add 1 withdrawal
example: "8"
description: Rate of withdrawals
example: "3"
maxWithdrawals:
type: string
description: Max withdrawals the bucket can hold
@ -2746,8 +2754,10 @@ components:
additionalProperties: false
required:
- ceilUSD
- blockStamp
- withdrawals
- blockWithdrawalRate
- rateBlocks
- rateWithdrawals
- maxWithdrawals
additionalProperties: false
required:

+ 6
- 4
common/ethrollup.go

@ -132,10 +132,12 @@ func (c *RollupConstants) FindVerifierIdx(MaxTx, NLevels int64) (int, error) {
// BucketParams are the parameter variables of each Bucket of Rollup Smart
// Contract
type BucketParams struct {
CeilUSD *big.Int
Withdrawals *big.Int
BlockWithdrawalRate *big.Int
MaxWithdrawals *big.Int
CeilUSD *big.Int
BlockStamp *big.Int
Withdrawals *big.Int
RateBlocks *big.Int
RateWithdrawals *big.Int
MaxWithdrawals *big.Int
}
// BucketUpdate are the bucket updates (tracking the withdrawals value changes)

+ 12
- 8
db/historydb/views.go

@ -354,10 +354,12 @@ type BucketUpdateAPI struct {
// BucketParamsAPI are the parameter variables of each Bucket of Rollup Smart
// Contract
type BucketParamsAPI struct {
CeilUSD *apitypes.BigIntStr `json:"ceilUSD"`
Withdrawals *apitypes.BigIntStr `json:"withdrawals"`
BlockWithdrawalRate *apitypes.BigIntStr `json:"blockWithdrawalRate"`
MaxWithdrawals *apitypes.BigIntStr `json:"maxWithdrawals"`
CeilUSD *apitypes.BigIntStr `json:"ceilUSD"`
BlockStamp *apitypes.BigIntStr `json:"blockstamp"`
Withdrawals *apitypes.BigIntStr `json:"withdrawals"`
RateBlocks *apitypes.BigIntStr `json:"rateBlocks"`
RateWithdrawals *apitypes.BigIntStr `json:"rateWithdrawals"`
MaxWithdrawals *apitypes.BigIntStr `json:"maxWithdrawals"`
}
// RollupVariablesAPI are the variables of the Rollup Smart Contract
@ -382,10 +384,12 @@ func NewRollupVariablesAPI(rollupVariables *common.RollupVariables) *RollupVaria
for i, bucket := range rollupVariables.Buckets {
rollupVars.Buckets[i] = BucketParamsAPI{
CeilUSD: apitypes.NewBigIntStr(bucket.CeilUSD),
Withdrawals: apitypes.NewBigIntStr(bucket.Withdrawals),
BlockWithdrawalRate: apitypes.NewBigIntStr(bucket.BlockWithdrawalRate),
MaxWithdrawals: apitypes.NewBigIntStr(bucket.MaxWithdrawals),
CeilUSD: apitypes.NewBigIntStr(bucket.CeilUSD),
BlockStamp: apitypes.NewBigIntStr(bucket.BlockStamp),
Withdrawals: apitypes.NewBigIntStr(bucket.Withdrawals),
RateBlocks: apitypes.NewBigIntStr(bucket.RateBlocks),
RateWithdrawals: apitypes.NewBigIntStr(bucket.RateWithdrawals),
MaxWithdrawals: apitypes.NewBigIntStr(bucket.MaxWithdrawals),
}
}
return &rollupVars

+ 34
- 29
eth/contracts/hermez/Hermez.go
File diff suppressed because it is too large
View File


+ 27
- 17
eth/rollup.go

@ -64,10 +64,12 @@ 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),
CeilUSD: big.NewInt(0),
BlockStamp: big.NewInt(0),
Withdrawals: big.NewInt(0),
RateBlocks: big.NewInt(0),
RateWithdrawals: big.NewInt(0),
MaxWithdrawals: big.NewInt(0),
}
}
return &common.RollupVariables{
@ -146,14 +148,16 @@ type RollupEventUpdateWithdrawalDelay struct {
// RollupUpdateBucketsParameters are the bucket parameters used in an update
type RollupUpdateBucketsParameters struct {
CeilUSD *big.Int
Withdrawals *big.Int
BlockWithdrawalRate *big.Int
MaxWithdrawals *big.Int
CeilUSD *big.Int
BlockStamp *big.Int
Withdrawals *big.Int
RateBlocks *big.Int
RateWithdrawals *big.Int
MaxWithdrawals *big.Int
}
type rollupEventUpdateBucketsParametersAux struct {
ArrayBuckets [common.RollupConstNumBuckets][4]*big.Int
ArrayBuckets [common.RollupConstNumBuckets][6]*big.Int
}
// 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(
arrayBuckets [common.RollupConstNumBuckets]RollupUpdateBucketsParameters,
) (tx *types.Transaction, err error) {
params := [common.RollupConstNumBuckets][4]*big.Int{}
params := [common.RollupConstNumBuckets][6]*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
params[i][1] = bucket.BlockStamp
params[i][2] = bucket.Withdrawals
params[i][3] = bucket.RateBlocks
params[i][4] = bucket.RateWithdrawals
params[i][5] = bucket.MaxWithdrawals
}
if tx, err = c.client.CallAuth(
12500000, //nolint:gomnd
@ -908,9 +914,11 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64,
}
for i, bucket := range bucketsParametersAux.ArrayBuckets {
bucketsParameters.ArrayBuckets[i].CeilUSD = bucket[0]
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[1]
bucketsParameters.ArrayBuckets[i].BlockWithdrawalRate = bucket[2]
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[3]
bucketsParameters.ArrayBuckets[i].BlockStamp = bucket[1]
bucketsParameters.ArrayBuckets[i].Withdrawals = bucket[2]
bucketsParameters.ArrayBuckets[i].RateBlocks = bucket[3]
bucketsParameters.ArrayBuckets[i].RateWithdrawals = bucket[4]
bucketsParameters.ArrayBuckets[i].MaxWithdrawals = bucket[5]
}
rollupEvents.UpdateBucketsParameters =
append(rollupEvents.UpdateBucketsParameters, bucketsParameters)
@ -932,8 +940,10 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64,
}
for i := range bucketsParameters.ArrayBuckets {
bucketsParameters.ArrayBuckets[i].CeilUSD = big.NewInt(0)
bucketsParameters.ArrayBuckets[i].BlockStamp = 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)
}
rollupEvents.UpdateBucketsParameters = append(rollupEvents.UpdateBucketsParameters,

+ 3
- 1
eth/rollup_test.go

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

+ 6
- 4
synchronizer/synchronizer.go

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

+ 6
- 4
test/ethclient.go

@ -304,10 +304,12 @@ func NewClientSetupExample() *ClientSetup {
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),
CeilUSD: big.NewInt(0),
BlockStamp: big.NewInt(0),
Withdrawals: big.NewInt(0),
RateBlocks: big.NewInt(0),
RateWithdrawals: big.NewInt(0),
MaxWithdrawals: big.NewInt(0),
}
}
rollupVariables := &common.RollupVariables{

Loading…
Cancel
Save