Original title: "Kava-3 Main Web Bug Fix Report"
Original author: Cava Lab
Abstract: At present, there is a minor bug on Kava's main website that will affect the adjustment of BEP3 asset supply, which means we cannot increase the airbnb mortgage amount in Kava CDP for now (it has reached the top of 40,000 BNB). Rest assured, however, that this bug will not affect the security of the user's money.
The Kava-3 network USES parameters to manage the state of the governance chain. By governing changes in parameters, Kava can manage how the main chain operates and respond quickly to timely emergencies with committee governance. We found a minor bug in one of the parameters, the asset supply limit of BEP3, which caused the parameter value change not to be implemented, meaning that the current supply replacement of 40,000BNB cannot be updated.
How to fix a bug?
The fix actually requires only a few lines of code to update, setting that when the value of the supplied limited parameter is updated, the state of the enforced application is updated accordingly. But yes, this is a big change to the system, so we can't just fix it by releasing a new V0.8 release.
How will the fix be implemented?
Preliminary network update
We've already written a software version that fixes this little bug. In bug fixes, we specify when the code will be executed. Validators need to update their outages before the specified time to ensure that the network is smoothly updated and no service interruption occurs. Any upstream legacy from the previous version of the software will be soft-bifurcated as the code takes effect. This is basically what the core Ethereum developers did with the "network upgrade."
Soft branch
Block chain refers to a network system version or protocol upgrade, the old routine will not be changed by the code, and continue to accept the block created by the new interrupt, the old stack will always work on the same chain.
Technical Code Appendix
Let's take a technical look at this bug in Kava code. The problem code is in Kava's BEp3 module. In the parameters of this module, the supported mortgage assets are specified as follows:
Type AssetParam struct {
& have spent Denom String 'JSON:' Denom 'YAML:' Denom '// Asset name
& have spent CoinID int 'json:' coin_id 'yaml:' coin_id '// internationally recognized CoinID
& have spent Yaml: "limit" '// Asset supply limits
& have spent Valid bool 'JSON: "Active" YAML: "active"' // indicates whether the asset is active or suspended
}
Making links:https://github.com/Kava-Labs/kava/blob/v0.8.1/x/bep3/types/params.go
Each mortgage asset imposes a limit - the maximum amount that asset can be pledged before the network limits further exchanges. When the main network is started, the following code sets an initial quota for each asset:
/ / initialization
_, supported assets: assets = range gs. The Params. SupportedAssets {
& have spent ZeroCoin: = SDk.newcoin (asset.denom, SDk.newint (0))
& have spent Supply: = NewAssetSupply (asset.Denom, zeroCoin, zeroCoin,
& have spent & have spent ZeroCoin, SDK.newcoin (asset.denom, asset.limit))
& have spent Keeper.SetAssetSupply (CTX, supply, [] byte (asset-Denom))
}
Making links:Https : & have spent / / github.com/Kava-Labs/kava/blob/v0.8.1/x/bep3/genesis.go#L29
The SetAssetSupply function sets a limit for each asset that applies contiguous 0x02 in the database:
// SetAssetSupply updates the current availability supply of the asset
Func (K Keeper) SetAssetSupply (CTX sdk.context, supply type.AssetSupply, noun [] byte) {
Store: = prefix.NewStore (prefix)
& have spent Ctx. KVStore (K.K.),
& have spent Types. AssetSupplyKeyPrefix, / / 0 x02
)
Bz: = final dc. MustMarshalBinaryLengthPrefixed (supply)
Store.Set (Denom, BZ)
}
Making links:https://github.com/Kava-Labs/kava/blob/869189054d68d6ec3e6446156ea0a91eb45af09c/x/bep3/keeper/keeper.go#L199
When the system updates the value of the assetparam.limit parameter, there is no corresponding function to update the value in the database (by calling SetAssetSupply). Therefore, update parameters are not passed to the application state.
When a new exchange was created, IncrementIncomingAssetSupply function is called, to check the exchange of assets quantity of no more than is stored in the corresponding 0 x02 asset amount limit. Currently the exchange does not pass this check because the value is not updated.
/ / IncrementIncomingAssetSupply incremental assets the incoming supply
Keeper function (k) IncrementIncomingAssetSupply (CTX SDK. The Context, "SDK. Coin) error {
& have spent = K.k. supply (CTX, [] byte (Coin.denom))
& have spent If you find {
& have spent & have spent Return sdkerrors. Wrap (types. ErrAssetNotSupported, coin. Denom)
& have spent }
& have spent // (the current + incoming + amount) result must be in the asset's
& have spent / / limit
& have spent TotalSupply: = supply.CurrentSupply.Add (supply.IncomingSupply)
& have spent
& have spent IsLT (totalSupply.Add (coin)) {supply.SupplyLimit).islt (totalSupply.Add (coin)) {
& have spent & have spent Return sdkerrors. Wrapf (
& have spent & have spent & have spent Types. ErrExceedsSupplyLimit,
& have spent & have spent & have spent "Increase % s, asset supply % s, limit % s",
& have spent & have spent & have spent Coin, totalSupply, supply. SupplyLimit,
& have spent & NBSP;)
& have spent }
.
Our fix is to add a function in the Bep3 Begin Blocker that updates the value of AssetSupply when the value in the parameter is updated.
// The BeginBlocker on each block will expire the atomic exchange,
// Remove closed exchanges from long-term storage (default storage time is 1 week) and update
// Governance of asset supply restrictions that may have changed.
Func BeginBlocker (CTX sdk.context, K Keeper) {
& have spent K.U pdateExpiredAtomicSwaps (CTX)
& have spent K.D eleteClosedAtomicSwapsFromLongtermStorage (CTX)
& have spent K.U pdateAssetSupplies (CTX)
}
The UpdateAssetSupply function adjusts the difference between the parameters and the values in the database, and sets the database to match the parameters.
// UpdateAssetSupplies updates the asset ceilings applied to from parameters to asset supplies
UpdateAssetSupplies (CTX SDk.context) Error {
& have spent = K.g.PARams (CTX) : PARAMS
& have spent : _, supportedAsset: = scope params.SupportedAssets {
& have spent & have spent Assets, find: = k.k. Supply (
& have spent & have spent & have spent CTX, [] Byte (Supportedasset-Denom),
& have spent & NBSP;)
& have spent & have spent If! Found {
& have spent & have spent & have spent Continue to
& have spent & have spent If asset.SupplyLimit.Amount! = supportedAsset. Limit {
& have spent & have spent & have spent Asset. SupplyLimit = SDK. NewCoin (
& have spent & have spent & have spent & have spent SupportedAsset Denom, & have spent & have spent & have spent & have spent SupportAsset. Limit .
& have spent & have spent & NBSP;)
K.s. Setsupply (CTX, Asset, [] Byte (Supportedasset-Denom))
& have spent & have spent }
& have spent }
& have spent Return nil
}
To implement this as an asynchronous network fork, we add an activation time parameter to the function that specifies when UpdateAssetSupplies should run. For example, we specify ctx.BlockTime () only. After (activationTime), run UpdateAssetSupply. Note that CTx. BlockTime () is the value of block chain time agreed by the verifier set and is not affected by clock drift.
Text link:https://mp.weixin.qq.com
Welcome to join the official BlockBeats community:
Telegram Subscription Group: https://t.me/theblockbeats
Telegram Discussion Group: https://t.me/BlockBeats_App
Official Twitter Account: https://twitter.com/BlockBeatsAsia