Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: virtual group and sp exit #284

Merged
merged 152 commits into from
Jul 7, 2023
Merged

Conversation

fynnss
Copy link
Contributor

@fynnss fynnss commented Jun 9, 2023

Description

In the previous design, the operator addresses of storage providers were directly stored in BucketInfo and ObjectInfo, resulting in a significant amount of metadata modification when a storage provider exited. To address this issue, we propose the concept of virtual groups. A virtual group consists of a primary storage provider and several secondary storage providers. Each object is associated with a virtual group, limiting the range of secondary storage providers for storing object replica data. This design offers several benefits. Firstly, it provides better support for bucket migration and storage provider exit, reducing the number of transactions required. Secondly, it reduces the size of metadata stored on the blockchain for both buckets and objects.

However, this proposal will have a huge impact on various existing modules and processes. The key changes are listed as follows:

  • A new additional module called Virtual Group Module, is responsible for managing all the virtual groups.
  • A new data location indexing format for object and storage provider
  • A new staking rule based on storage size for a storage provider
  • A new stream payment path based on a virtual group payment account

Virtual Group Module

We will introduce a new module to manage all virtual groups. The number of storage providers in each virtual group is determined by the redundancy policy. E.g If our redundancy policy specifies a full replica and a 4+2 erasure coding (EC) replica tree, so every virtual group should have one primary sp and six secondary sp.

Terminology

Global Virtual Group (GVG): A global virtual group consists of one primary SP (SP) and multiple secondary SPs.
Local Virtual Group(LVG): Each bucket maintains a mapping from the local group ID to the global group ID. j(e.g 3 ➝ 001960583).
Virtual Group Family(VGF): Each primary storage provider can create multiple virtual group families, with each family containing several global virtual groups. Each family serves a limited number of buckets. Once the store size exceeds a specified threshold, the family will no longer allow to serve more buckets.

Relationships

Local virtual groups are linked to their corresponding buckets, and each object needs to store the ID information of the local virtual group. Each local virtual group must correspond to one and only one global virtual group.
image

In order to avoid all the data of a primary SP being transferred to one SP within a short period of time, we introduce the concept of "family". 
image

A family can contain multiple GVG that the same SP creates. A bucket can only be served by the GVGs that are in the same family, cross family GVG is not allowed within one bucket. Once the total storage size of a family exceeds 64TB(TBD), the GVG inside the family can not server new buckets, the SP has to create a new family. By introducing family , the primary SP can exit at family level without breaking the one bucket, one primary SP rule.

[Need confirm] When all GVGs within a family become unavailable and it's not possible to create new GVGs and add them to the family, how to handle this situation?

Staking

We introduce a new staking rule based on storage size. The minimum required staking tokens can be calculated using the formula storage_staking_price * stored_size . The storage providers have the option to pre-stake tokens for upcoming storage if needed.

All staking tokens will be managed by the Virtual Group Module account. Only during deletion or swapping out, the storage providers can get these staking tokens back. In the event of a storage provider's forced exit, these tokens will be forfeited and used to reward those storage providers which take over these GVG.

SP Exit

  1. The Storage Provider (SP1), initiates the exit process by submitting a StorageProviderExit transaction to the blockchain.
  2. The SP1 or its successor SP must then repeatedly call SwapOut to remove itself from all Global Virtual Groups (GVGs).
  • For the primary SP, the swap-out process occurs at the family level to ensure there are no conflicts with other SPs within the GVG.
  • For secondary SPs, the swap-out happens at the GVG level and must also avoid conflicts with the primary SP.
  1. Once the SP1 has successfully completed the swap-out process from all GVGs, it can submit a CompleteStorageProviderExit transaction to retrieve the staked tokens.

Bucket Migration

image

  1. The user submits a bucket migration transaction with the signature of the new primary SP.
  2. The new SP starts receiving full data from the old primary SP or from secondary SPs.
  3. The new SP distributes data among the secondary SPs according to his new GVPs. (more details required...)
  4. The new SP submit a bucket seal transaction on-chain along with all the aggregate signature from new secondary SPs.
  5. The on-chain module will:
  • Unbind the old LVG and GVG mapping, and build a new mapping relationship.
  • Settle the payment stream between LVG, GVF, and SPs.
  1. During the migration period, the user can not upload files to this bucket.
  2. During the migration period, the old SP should still serve the query request.

Rationale

This solution can significantly reduce the amount of meta data modifications when the service provider (SP) exits or during bucket migration.

Example

NA

Changes

Notable changes:

  • NA

}
}

if k.ExistsAutoResumeRecord(ctx, record.Timestamp, addr) { // this check should be cheap usually
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that a streamrecord is STREAM_ACCOUNT_STATUS_ACTIVE and still ExistsAutoResumeRecord?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, when the stream is changed to active, the related AutoResumeRecord will be deleted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the case, why dont we use the status of stream record to replace the ExistsAutoResumeRecord condition here?

@fynnss fynnss changed the base branch from develop to feat_sp_exit_develop July 6, 2023 13:18
@fynnss fynnss merged commit bd38cd8 into feat_sp_exit_develop Jul 7, 2023
fynnss added a commit that referenced this pull request Jul 11, 2023
* init virtual group module

* add create/delete/deposit/withdraw/swapout messages

* add sp keeper dependency

* add router and type function

* refactor sequence to support uint32 and U256

* impl virtual group module

* refactor storage module

* refactor challenge module to algin the new design

* self review code

* fix testcase and punish code

* fix challenge testcases

* refactor payment module to algin the new design

* add e2e test

* fix some unit tests

* update cosmos-sdk

* update go mod

* fix e2e test

* store deposit

* update gomod

* fix some e2e test case

* fix cancel create object

* ignore error for testing

* fix storage test

* fix test case

* make GetGVG more simple

* add virtual group swap out message

* fix swap out

* add event

* fix ignite missing placeholder

* add sp exit message

* add sp exit

* complete sp exit

* add swap deposit

* remove virtual payment account from local virtual group/ event

* complete sp exit process

* fix mock file error

* add mock gen

* fix swap out as secondary sp error

* refator payment

* refactor approval to get more extends

* fix payment unit test

* add withdraw cli

* revert extends of approval

* refactor payment for settlement and resume

* refactor payment for out flow

* fix proto

* add basic migration bucket logic

* fix the sp exit

* refine the code

* add payment for bucket migration

* refactor code

* fix some issues

* fix issue and unit tests

* add migration check and rebinding

* refine the code

* refactor withdraw from gvg & gvg family

* feat: use bls sig in sealObject by secondary sps (#283)

* fix gensp test error

* add more check and params

* add some unit tests for payment

* fix compile error

* add exit,completeexit, swapout events

* add migration event

* add create gvg family event

* mirror update

* fix lint issues

* fix lint issues

* fix some unit tests

* fix the limit of gvgs and lvgs

* fix bucket migration

* fix address issues for new messages

* refine challenge module

* refine payment module

* fix basesuite for create so many families

* fix lint

* add deposit/withdraw test for virtual group

* fix issue of iterator

* add basic sp exit test and fix some bugs

* fix issue and refactor e2e tests

* add e2e test cases

* fix and add e2e test cases

* refactor e2e test

* add sp swap out test

* refine code by cr

* fix some review comments

* fix cr suggestion

* fix some review comments

* refine the code

* calculate sp num instead of constant

* add migration e2e test

* feat: bls sig for complete migrate bucket (#291)

* fix bucket migration issue

* update cosmos sdk version

* fix migration bucket e2e test

* fix CodeReview issues

* fix some bugs

* update staking per GB

* refine some var

* fix RebindingGVGsToBucket revert error

* feat: Local virtual group and Billing info refacot (#306)

* fix challenge refactor

* fix some review tips

* fix internal bucket info error

* add family id to CreateBucketEvent

* refactor challenge module

* refactor payment module

* fix redundany GenId

* add family id check

* refactor payment module

* fix error

* refactor payment module

* fix issue

* implement virtual group cmd

* refine the comments of protobuf

* fix e2e test

* remove some useless code

* fix sp exit test

* add more sp exit test and fix some bugs

* using id instead of address for some interfaces and events

* fix some tests

* fix e2e

* fix unit test

* add more check and parmas check

* fix e2e tests

* fix an issue

* fix sp test

* fix ci lint

* remove useless code (#308)

* chore: refine payment for gvg settle (#309)

* chore: refine gvg staking per bytes and default params (#310)

* rename gvgstakingprice to gvgstakingperbytes

* fix DefaultMaxStoreSizePerFamily

* feat: add chainId to bls sign doc (#313)

* add chainId to bls sign doc

* get chain id from cosmos context

* feat: refine swap out and migrate bucket (#311)

* fix: update swagger (#317)

* feat: enhance head object api (#321)

* fix gnfd query api (#318)

* feat: update challenge and stop serving for sp exit (#322)

* feat: fix review comments of sp exit (#320)

* fix code review tips (#325)

* fix cosmos sdk version

* fix e2e test case

* fix review tips
fynnss added a commit that referenced this pull request Jul 13, 2023
* init virtual group module

* add create/delete/deposit/withdraw/swapout messages

* add sp keeper dependency

* add router and type function

* refactor sequence to support uint32 and U256

* impl virtual group module

* refactor storage module

* refactor challenge module to algin the new design

* self review code

* fix testcase and punish code

* fix challenge testcases

* refactor payment module to algin the new design

* add e2e test

* fix some unit tests

* update cosmos-sdk

* update go mod

* fix e2e test

* store deposit

* update gomod

* fix some e2e test case

* fix cancel create object

* ignore error for testing

* fix storage test

* fix test case

* make GetGVG more simple

* add virtual group swap out message

* fix swap out

* add event

* fix ignite missing placeholder

* add sp exit message

* add sp exit

* complete sp exit

* add swap deposit

* remove virtual payment account from local virtual group/ event

* complete sp exit process

* fix mock file error

* add mock gen

* fix swap out as secondary sp error

* refator payment

* refactor approval to get more extends

* fix payment unit test

* add withdraw cli

* revert extends of approval

* refactor payment for settlement and resume

* refactor payment for out flow

* fix proto

* add basic migration bucket logic

* fix the sp exit

* refine the code

* add payment for bucket migration

* refactor code

* fix some issues

* fix issue and unit tests

* add migration check and rebinding

* refine the code

* refactor withdraw from gvg & gvg family

* feat: use bls sig in sealObject by secondary sps (#283)

* fix gensp test error

* add more check and params

* add some unit tests for payment

* fix compile error

* add exit,completeexit, swapout events

* add migration event

* add create gvg family event

* mirror update

* fix lint issues

* fix lint issues

* fix some unit tests

* fix the limit of gvgs and lvgs

* fix bucket migration

* fix address issues for new messages

* refine challenge module

* refine payment module

* fix basesuite for create so many families

* fix lint

* add deposit/withdraw test for virtual group

* fix issue of iterator

* add basic sp exit test and fix some bugs

* fix issue and refactor e2e tests

* add e2e test cases

* fix and add e2e test cases

* refactor e2e test

* add sp swap out test

* refine code by cr

* fix some review comments

* fix cr suggestion

* fix some review comments

* refine the code

* calculate sp num instead of constant

* add migration e2e test

* feat: bls sig for complete migrate bucket (#291)

* fix bucket migration issue

* update cosmos sdk version

* fix migration bucket e2e test

* fix CodeReview issues

* fix some bugs

* update staking per GB

* refine some var

* fix RebindingGVGsToBucket revert error

* feat: Local virtual group and Billing info refacot (#306)

* fix challenge refactor

* fix some review tips

* fix internal bucket info error

* add family id to CreateBucketEvent

* refactor challenge module

* refactor payment module

* fix redundany GenId

* add family id check

* refactor payment module

* fix error

* refactor payment module

* fix issue

* implement virtual group cmd

* refine the comments of protobuf

* fix e2e test

* remove some useless code

* fix sp exit test

* add more sp exit test and fix some bugs

* using id instead of address for some interfaces and events

* fix some tests

* fix e2e

* fix unit test

* add more check and parmas check

* fix e2e tests

* fix an issue

* fix sp test

* fix ci lint

* remove useless code (#308)

* chore: refine payment for gvg settle (#309)

* chore: refine gvg staking per bytes and default params (#310)

* rename gvgstakingprice to gvgstakingperbytes

* fix DefaultMaxStoreSizePerFamily

* feat: add chainId to bls sign doc (#313)

* add chainId to bls sign doc

* get chain id from cosmos context

* feat: refine swap out and migrate bucket (#311)

* fix: update swagger (#317)

* feat: enhance head object api (#321)

* fix gnfd query api (#318)

* feat: update challenge and stop serving for sp exit (#322)

* feat: fix review comments of sp exit (#320)

* fix code review tips (#325)

* fix cosmos sdk version

* fix e2e test case

* fix review tips
fynnss added a commit that referenced this pull request Jul 13, 2023
* init virtual group module

* add create/delete/deposit/withdraw/swapout messages

* add sp keeper dependency

* add router and type function

* refactor sequence to support uint32 and U256

* impl virtual group module

* refactor storage module

* refactor challenge module to algin the new design

* self review code

* fix testcase and punish code

* fix challenge testcases

* refactor payment module to algin the new design

* add e2e test

* fix some unit tests

* update cosmos-sdk

* update go mod

* fix e2e test

* store deposit

* update gomod

* fix some e2e test case

* fix cancel create object

* ignore error for testing

* fix storage test

* fix test case

* make GetGVG more simple

* add virtual group swap out message

* fix swap out

* add event

* fix ignite missing placeholder

* add sp exit message

* add sp exit

* complete sp exit

* add swap deposit

* remove virtual payment account from local virtual group/ event

* complete sp exit process

* fix mock file error

* add mock gen

* fix swap out as secondary sp error

* refator payment

* refactor approval to get more extends

* fix payment unit test

* add withdraw cli

* revert extends of approval

* refactor payment for settlement and resume

* refactor payment for out flow

* fix proto

* add basic migration bucket logic

* fix the sp exit

* refine the code

* add payment for bucket migration

* refactor code

* fix some issues

* fix issue and unit tests

* add migration check and rebinding

* refine the code

* refactor withdraw from gvg & gvg family

* feat: use bls sig in sealObject by secondary sps (#283)

* fix gensp test error

* add more check and params

* add some unit tests for payment

* fix compile error

* add exit,completeexit, swapout events

* add migration event

* add create gvg family event

* mirror update

* fix lint issues

* fix lint issues

* fix some unit tests

* fix the limit of gvgs and lvgs

* fix bucket migration

* fix address issues for new messages

* refine challenge module

* refine payment module

* fix basesuite for create so many families

* fix lint

* add deposit/withdraw test for virtual group

* fix issue of iterator

* add basic sp exit test and fix some bugs

* fix issue and refactor e2e tests

* add e2e test cases

* fix and add e2e test cases

* refactor e2e test

* add sp swap out test

* refine code by cr

* fix some review comments

* fix cr suggestion

* fix some review comments

* refine the code

* calculate sp num instead of constant

* add migration e2e test

* feat: bls sig for complete migrate bucket (#291)

* fix bucket migration issue

* update cosmos sdk version

* fix migration bucket e2e test

* fix CodeReview issues

* fix some bugs

* update staking per GB

* refine some var

* fix RebindingGVGsToBucket revert error

* feat: Local virtual group and Billing info refacot (#306)

* fix challenge refactor

* fix some review tips

* fix internal bucket info error

* add family id to CreateBucketEvent

* refactor challenge module

* refactor payment module

* fix redundany GenId

* add family id check

* refactor payment module

* fix error

* refactor payment module

* fix issue

* implement virtual group cmd

* refine the comments of protobuf

* fix e2e test

* remove some useless code

* fix sp exit test

* add more sp exit test and fix some bugs

* using id instead of address for some interfaces and events

* fix some tests

* fix e2e

* fix unit test

* add more check and parmas check

* fix e2e tests

* fix an issue

* fix sp test

* fix ci lint

* remove useless code (#308)

* chore: refine payment for gvg settle (#309)

* chore: refine gvg staking per bytes and default params (#310)

* rename gvgstakingprice to gvgstakingperbytes

* fix DefaultMaxStoreSizePerFamily

* feat: add chainId to bls sign doc (#313)

* add chainId to bls sign doc

* get chain id from cosmos context

* feat: refine swap out and migrate bucket (#311)

* fix: update swagger (#317)

* feat: enhance head object api (#321)

* fix gnfd query api (#318)

* feat: update challenge and stop serving for sp exit (#322)

* feat: fix review comments of sp exit (#320)

* fix code review tips (#325)

* fix cosmos sdk version

* fix e2e test case

* fix review tips
@fynnss fynnss deleted the virtual_group_dev branch July 21, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants