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: implement BEP-333(BNB Chain Fusion) #381

Merged
merged 21 commits into from
Feb 26, 2024
Merged

feat: implement BEP-333(BNB Chain Fusion) #381

merged 21 commits into from
Feb 26, 2024

Conversation

j75689
Copy link
Collaborator

@j75689 j75689 commented Jan 15, 2024

Description

Implement the functions for the BC-Fusion plan.

The Beacon Chain in the BC-Fusion plan consists of four stages:

  1. FirstSunsetFork - Disable Certain Message Types:
    In this stage, the system will disable specific message types to prevent users from creating additional assets on the Beacon Chain. The following Msgs will be disabled:

    • TimeLockMsg
    • TimeRelockMsg
    • FreezeMsg
    • IssueMsg
    • MintMsg
    • IssueMiniMsg
    • HTLTMsg
    • DepositHTLTMsg
    • MsgSideChainDelegate
    • MsgSideChainRedelegate
    • MsgCreateSideChainValidator
    • MsgCreateSideChainValidatorWithVoteAddr
    • MsgEditSideChainValidator
    • MsgEditSideChainValidatorWithVoteAddr

    MsgSideChainStakeMigration will be enabled to allow users to redelegate tokens to BSC.
    MsgSideChainSubmitProposal will be disabled after the SideChain Total Voting Power falls below 5M BNB.

  2. SecondSunsetFork - Token Refunding:
    During this stage, the system will process token refunds for users who have assets locked on the Beacon Chain. Refunds will be initiated for TimeLock, AtomicSwap, and Delegation on the side chain. MsgSideChainUndelegate on the Beacon Chain will be disabled to prevent undelegation and ensure system efficiency.

  3. FinalSunsetFork - Closure of Cross-Chain Channels:
    This marks the final stage of BC-Fusion. The system will close all cross-chain channels. After the FinalSunsetFork, the system will no longer support cross-chain transactions.

  4. Token Migration:
    After the FinalSunsetFork, users may still have assets on the Beacon Chain. The system will support token migration, allowing users to move their assets to BSC. For detailed instructions, please refer to BEP-299.

Rationale

For the reasoning behind this plan, refer to BEP-333.

Example

n/a

Notable Changes

  • Tokens
  • Staking
  • Governance
  • IBC

j75689 and others added 17 commits November 29, 2023 17:20
)

* fix: handleMsgSideChainUndelegate should not pass prefixCtx

* fix: nil pointer when doing ibc method in endblock
* feat: add `MsgSideChainStakeMigration` and `StakeMigrationApp`

* add missing tag

* fix `handleMsgSideChainStakeMigration`

* fix review comments

* rename `MsgTypeSideChainStakeMigration`

* add fee param for `MsgSideChainStakeMigration`
…nPackage and prevent too many failed in auto refund (#377)

* feat: add IsAutoUnDelegate field to CrossStakeDistributeUndelegatedSynPackage

* fix: disable undelegate after SecondSunsetFork and prevent too many failed in auto refund

* chore: add more logs

* revert: cross stake changes

* fix: error handling in refund

* fix: transferPackage

* fix: CrossStakeDistributeUndelegatedSynPackageV2
…unsetFork (#379)

* fix: do not charge relayerFee for auto cross undelegate after SecondSunsetFork

* fix: FeeCalculator
@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2024

Codecov Report

Merging #381 (dc761f4) into develop (5a7b238) will decrease coverage by 0.71%.
The diff coverage is 6.22%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #381      +/-   ##
===========================================
- Coverage    45.82%   45.12%   -0.71%     
===========================================
  Files          248      249       +1     
  Lines        24263    24671     +408     
===========================================
+ Hits         11119    11132      +13     
- Misses       12476    12867     +391     
- Partials       668      672       +4     

@@ -40,19 +43,42 @@ func NewHandler(k keeper.Keeper, govKeeper gov.Keeper) sdk.Handler {
return handleMsgUndelegate(ctx, msg, k)
// case MsgSideChain
case types.MsgCreateSideChainValidator:
if sdk.IsUpgrade(sdk.FirstSunsetFork) {
return sdk.ErrMsgNotSupported("").Result()
}
return handleMsgCreateSideChainValidator(ctx, msg, k)
case types.MsgEditSideChainValidator:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why MsgEditSideChainValidator is not disabled like MsgEditSideChainValidatorWithVoteAddr?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

accept

Copy link
Collaborator Author

@j75689 j75689 Jan 26, 2024

Choose a reason for hiding this comment

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

image `SideConsAddr` edition was allowed by BEP159, user can only change consAddr on testnet.

}, k)
refundEvents = refundEvents.AppendEvents(result.Events)
if !result.IsOK() {
ctx.Logger().Debug("handleRefundStake failed",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Debug level enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe Info level would be better

Amount: bscTransferAmount,
Recipient: recipient,
Validator: valAddr,
IsAutoUnDelegate: k.IsAutoUnDelegate(ctx, delAddr, valAddr),
Copy link
Contributor

Choose a reason for hiding this comment

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

IsAutoUnDelegate is called twice in the func. Maybe we can have a local variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

accept

// this is to prevent too many delegation is in unbounded state
// if too many delegation is in unbounded state, it will cause too many iteration in the block
failedCount++
if failedCount >= maxProcessedRefundFailed {
Copy link
Contributor

Choose a reason for hiding this comment

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

At the edge case, when we reach maxProcessedRefundFailed, we cannot refund any records even in the following blocks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that is expected, if too many user undelegate by themself, we should wait for them to be completed.
but don't worry, undelegate is disable after secondSunsetFork, so the max time we wait for is 7days.

@unclezoro unclezoro merged commit 46d2616 into develop Feb 26, 2024
2 checks passed
unclezoro added a commit that referenced this pull request Feb 26, 2024
* fix: fix nil validator when publishing message (#356)

* feat: implement BEP-333(BNB Chain Fusion) (#381)

* feat: bc fusion hardfork implementation (#358)

* fix: panic issue when doing refundStake and closeCorssChainChannel (#362)

* fix: handleMsgSideChainUndelegate should not pass prefixCtx

* fix: nil pointer when doing ibc method in endblock

* fix: add logs to sunset fork events and immediate sidechain undelegation (#364)

* fix: revert immediate sidechain undelegation and handle undelegation in endblock (#365)

* fix: disable ClaimMsg after FinalSunsetFork (#366)

* feat: add `MsgSideChainStakeMigration` and `StakeMigrationApp` (#367)

* feat: add `MsgSideChainStakeMigration` and `StakeMigrationApp`

* add missing tag

* fix `handleMsgSideChainStakeMigration`

* fix review comments

* rename `MsgTypeSideChainStakeMigration`

* add fee param for `MsgSideChainStakeMigration`

* fix: add missing register for new msg (#368)

* fix: error within `CreateRawIBCPackageByIdWithFee` (#369)

* fix: decimal for BCFusionStopGovThreshold (#370)

* fix: panic when totally unbound the validator in voting period (#371)

* fix: add missing event (#372)

* fix: wrong json tag (#373)

* fix: add missing tag of relayer fee in `handleMsgSideChainStakeMigration` (#376)

* feat: add IsAutoUnDelegate field to CrossStakeDistributeUndelegatedSynPackage and  prevent too many failed in auto refund (#377)

* feat: add IsAutoUnDelegate field to CrossStakeDistributeUndelegatedSynPackage

* fix: disable undelegate after SecondSunsetFork and prevent too many failed in auto refund

* chore: add more logs

* revert: cross stake changes

* fix: error handling in refund

* fix: transferPackage

* fix: CrossStakeDistributeUndelegatedSynPackageV2

* fix: reset context every time in refund loop (#378)

* fix: do not charge relayerFee for auto cross undelegate after SecondSunsetFork (#379)

* fix: do not charge relayerFee for auto cross undelegate after SecondSunsetFork

* fix: FeeCalculator

* chore: add logs for processed refunding count (#380)

* fix: close mirror, mirrorSync channel after FinalSunsetFork (#382)

* fix: disable MsgEditSideChainValidator after FirstSunsetFork and refine codes (#383)

* fix: change StakeMigrationRelayFee to 0.002BNB (#384)

* fix: appHash mismatch causes by channelsMap (#385)

---------

Co-authored-by: Roshan <[email protected]>

* docs: add change logs for release 0.26.7 (#386)

---------

Co-authored-by: forcodedancing <[email protected]>
Co-authored-by: dylanhuang <[email protected]>
Co-authored-by: Roshan <[email protected]>
Copy link

@TheManager73 TheManager73 left a comment

Choose a reason for hiding this comment

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

Status
Migrated
Self Stake
0
Latest Delegators
698
Since Time
2021-03-04
Operator Address
bva1t42gtf6hawqgpmdpjzmvlzvmlttlqtkvlmgjxt
Self Delegate Address
bnb1weh5t6q0qf0nxpnj6flru9g9gdw9wkzm9hrtqn
Consensus Address
0x70F657164e5b75689b64B7fd1fA275F334f28e18
Fee Address
0x5CF5d69852151952b1b1faF04d9B6140dAe30aFD

QN_bffccb7aa66044ee96fc6c817aae0052
perate Since
2024-04-18
Type
Cabinet
Website
https://bscscan.com/
Self Delegation
2,253.6828367024464 BNB
Delegators
36
Operator Address
0x0C5c5472...86f66D3A54

Consensus Address
0x502aECFE...FeD0Fe16a0

Vote Address
0xb15df589...ef5b8054ab

Identity
0xd8830be9...12289cd7af

{
"validatorSrcAddr": "bva1t42gtf6hawqgpmdpjzmvlzvmlttlqtkvlmgjxt",
"validatorDstAddr": "0x0c5c547215c6516603c3de9525abef86f66d3a54",
"delegatorAddr": "0x689f25d1292daf08988941ae1ce509ba4d18c1cd",
"refundAddr": "bnb1weh5t6q0qf0nxpnj6flru9g9gdw9wkzm9hrtqn",
"amount": {
"amount": 4995000000000,
"denom": "BNB"
}
}
/**
*Submitted for verification at BscTrace on 2024-06-07
*/

@TheManager73
Copy link

}
0x7777772e636f696e626173652e636f6d2077616e747320796f7520746f207369676e20696e207769746820796f757220457468657265756d206163636f756e743a0a3078463534626236616431393142443235643135433930363536656566646641333430646345423737630a0a506c65617365207369676e2074686973206d65737361676520746f20636f6e6669726d206f776e657273686970206f6620746869732077616c6c65742e0a0a5552493a2068747470733a2f2f7777772e636f696e626173652e636f6d2f6f6e636861696e2d7665726966790a56657273696f6e3a20310a436861696e2049443a20383435330a4e6f6e63653a2070737a7069736634577a3876787337680a4973737565642041743a20323032342d30372d30395430383a32363a32365a0a45787069726174696f6e2054696d653a20323032342d30372d30395430383a33313a32365a",
"0xF54bb6ad191BD25d15C90656eefdfA340dcEB77c"
]

]
organizations/40166415-efac-48a0-899c-33873249eb95/apiKeys/d56ef5db-01c4-45dc-b1ce-ab15da785d5f

-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIHW4I8y8o5Ll0/N/8rcjgm5W7me3Dq7ekGFr41BE2dvRoAoGCCqGSM49\nAwEHoUQDQgAEWdVCMv7PmdK/d9xI8Mt3E1RejGjZ0VnwjPGuokpNQQBlVcHlkjlQ\nVpqmUga8b1d65NqEmATnqXnlhMOtDt1uUQ==\n-----END EC PRIVATE KEY-----\n

https://bscscan.com/address/0x0000000000000000000000000000000000001000#readContract#F2

{
"description": {
"moniker": "BscScan",
"identity": "",
"website": "https://bscscan.com",
"details": "Your Gateway to the Binance Smart Chain Network. BscScan is the leading BSC Block Chain Explorer and one of the earliest independent project built and developed for the Binance Smart Chain"
},
"validatorAddress": "bva1t42gtf6hawqgpmdpjzmvlzvmlttlqtkvlmgjxt",
"commissionRate": 10000000,
"sideChainId": "bsc",
"sideFeeAddr": "0x5cf5d69852151952b1b1faf04d9b6140dae30afd"
}

{
"description": {
"moniker": "BscScan",
"identity": "",
"website": "https://bscscan.com",
"details": "Your Gateway to the Binance Smart Chain Network. BscScan is the leading BSC Block Chain Explorer and one of the earliest independent project built and developed for the Binance Smart Chain"
},
"commission": {
"rate": 25000000,
"maxRate": 90000000,
"maxChangeRate": 80000000,
"updateTimeInMs": 0
},
"delegatorAddr": "bnb1weh5t6q0qf0nxpnj6flru9g9gdw9wkzm9hrtqn",
"validatorAddr": "bva1t42gtf6hawqgpmdpjzmvlzvmlttlqtkvlmgjxt",
"delegation": {
"amount": 5000000000000,
"denom": "BNB"
},
"sideChainId": "bsc",
"sideConsAddr": "0x70f657164e5b75689b64b7fd1fa275f334f28e18",
"sideFeeAddr": "0x5cf5d69852151952b1b1faf04d9b6140dae30afd"
}

Copy link

@hasti0073 hasti0073 left a comment

Choose a reason for hiding this comment

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

    • **```

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.

8 participants