Skip to content

Commit b9309fc

Browse files
committed
Optimize the acquisition of subnet information in alpha_token
1 parent 7f957b9 commit b9309fc

File tree

3 files changed

+11
-37
lines changed

3 files changed

+11
-37
lines changed

x/blockinflation/keeper/alpha_token.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ import (
1616

1717
// MintAlphaTokens mints alpha tokens to the specified address
1818
func (k Keeper) MintAlphaTokens(ctx sdk.Context, netuid uint16, recipient string, amount uint64) error {
19-
// 1. Get the subnet info to find the AlphaToken address
19+
// 1. Get the subnet to find information about it
2020
subnet, found := k.eventKeeper.GetSubnet(ctx, netuid)
2121
if !found {
2222
return fmt.Errorf("subnet not found: %d", netuid)
2323
}
2424

25-
subnetInfo, found := getSubnetInfo(subnet)
26-
if !found || subnetInfo.AlphaToken == "" {
27-
return fmt.Errorf("subnet has no alpha token: %d", netuid)
25+
// 2. Check if the subnet has an AlphaToken address in its params
26+
alphaTokenAddress, ok := subnet.Params["alpha_token"]
27+
if !ok || alphaTokenAddress == "" {
28+
return fmt.Errorf("subnet has no alpha token address in params: %d", netuid)
2829
}
2930

3031
// 3. Parse the AlphaToken address
31-
alphaTokenAddr := common.HexToAddress(subnetInfo.AlphaToken)
32+
alphaTokenAddr := common.HexToAddress(alphaTokenAddress)
3233
if (alphaTokenAddr == common.Address{}) {
33-
return fmt.Errorf("invalid alpha token address: %s", subnetInfo.AlphaToken)
34+
return fmt.Errorf("invalid alpha token address: %s", alphaTokenAddress)
3435
}
3536

3637
// 4. Get the AlphaToken ABI

x/blockinflation/keeper/coinbase.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,15 @@ func (k Keeper) RunCoinbase(ctx sdk.Context, blockEmission math.Int) error {
277277
}
278278
if ownerCut.IsPositive() {
279279
k.Logger(ctx).Info("Owner cut distributed", "netuid", netuid, "amount", ownerCut.String())
280-
subnetInfo, found := getSubnetInfo(subnet)
281-
if !found {
282-
k.Logger(ctx).Error("Failed to get subnet info for owner cut",
283-
"netuid", netuid,
284-
"amount", ownerCut.Uint64(),
285-
)
286-
continue
287-
}
288-
if err := k.MintAlphaTokens(ctx, netuid, subnetInfo.Owner, ownerCut.Uint64()); err != nil {
280+
// 铸造 Alpha 代币给子网所有者
281+
if err := k.MintAlphaTokens(ctx, netuid, subnet.Owner, ownerCut.Uint64()); err != nil {
289282
k.Logger(ctx).Error("Failed to mint alpha tokens for subnet owner",
290283
"netuid", netuid,
291-
"owner", subnetInfo.Owner,
284+
"owner", subnet.Owner,
292285
"amount", ownerCut.Uint64(),
293286
"error", err,
294287
)
288+
// 继续处理,不中断流程
295289
}
296290
}
297291
} else {

x/blockinflation/keeper/subnet_utils.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)