Skip to content

Commit 42c4bee

Browse files
committed
Fixes after audit
1 parent 6f9fef4 commit 42c4bee

File tree

15 files changed

+131
-67
lines changed

15 files changed

+131
-67
lines changed

avalanchego/api/info/service.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ func (i *Info) Uptime(_ *http.Request, _ *struct{}, reply *UptimeResponse) error
330330
}
331331

332332
type ACP struct {
333-
SupportWeight *big.Int `json:"supportWeight"`
333+
SupportWeight json.BigInt `json:"supportWeight"`
334334
Supporters set.Set[ids.NodeID] `json:"supporters"`
335-
ObjectWeight *big.Int `json:"objectWeight"`
335+
ObjectWeight json.BigInt `json:"objectWeight"`
336336
Objectors set.Set[ids.NodeID] `json:"objectors"`
337-
AbstainWeight *big.Int `json:"abstainWeight"`
337+
AbstainWeight json.BigInt `json:"abstainWeight"`
338338
}
339339

340340
type ACPsReply struct {
@@ -344,7 +344,11 @@ type ACPsReply struct {
344344
func (a *ACPsReply) getACP(acpNum uint32) *ACP {
345345
acp, ok := a.ACPs[acpNum]
346346
if !ok {
347-
acp = &ACP{}
347+
acp = &ACP{
348+
SupportWeight: json.NewBigIntFromInt(0),
349+
ObjectWeight: json.NewBigIntFromInt(0),
350+
AbstainWeight: json.NewBigIntFromInt(0),
351+
}
348352
a.ACPs[acpNum] = acp
349353
}
350354
return acp
@@ -367,19 +371,19 @@ func (i *Info) Acps(_ *http.Request, _ *struct{}, reply *ACPsReply) error {
367371
for acpNum := range peer.SupportedACPs {
368372
acp := reply.getACP(acpNum)
369373
acp.Supporters.Add(peer.ID)
370-
acp.SupportWeight = new(big.Int).Add(acp.SupportWeight, new(big.Int).SetUint64(weight))
374+
acp.SupportWeight.Set(new(big.Int).Add(acp.SupportWeight.ToBigInt(), new(big.Int).SetUint64(weight)))
371375
}
372376
for acpNum := range peer.ObjectedACPs {
373377
acp := reply.getACP(acpNum)
374378
acp.Objectors.Add(peer.ID)
375-
acp.ObjectWeight = new(big.Int).Add(acp.ObjectWeight, new(big.Int).SetUint64(weight))
379+
acp.ObjectWeight.Set(new(big.Int).Add(acp.ObjectWeight.ToBigInt(), new(big.Int).SetUint64(weight)))
376380
}
377381
}
378382

379383
totalWeight := i.validators.TotalWeight(constants.PrimaryNetworkID)
380384
for acpNum := range constants.CurrentACPs {
381385
acp := reply.getACP(acpNum)
382-
acp.AbstainWeight = new(big.Int).Sub(totalWeight, new(big.Int).Add(acp.SupportWeight, acp.ObjectWeight))
386+
acp.AbstainWeight.Set(new(big.Int).Sub(totalWeight, new(big.Int).Add(acp.SupportWeight.ToBigInt(), acp.ObjectWeight.ToBigInt())))
383387
}
384388
return nil
385389
}

avalanchego/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ func getStakingConfig(v *viper.Viper, networkID uint32) (node.StakingConfig, err
763763
}
764764

765765
func getTxFeeConfig(v *viper.Viper, networkID uint32) genesis.TxFeeConfig {
766-
if networkID != constants.MainnetID {
766+
if networkID == constants.LocalFlareID || networkID == constants.LocalID {
767767
return genesis.TxFeeConfig{
768768
CreateAssetTxFee: v.GetUint64(CreateAssetTxFeeKey),
769769
StaticFeeConfig: txfee.StaticConfig{

avalanchego/database/helpers.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/binary"
88
"errors"
99
"fmt"
10-
"math/big"
1110
"time"
1211

1312
"github.com/ava-labs/avalanchego/ids"
@@ -68,18 +67,6 @@ func ParseUInt64(b []byte) (uint64, error) {
6867
return binary.BigEndian.Uint64(b), nil
6968
}
7069

71-
func GetBigInt(db KeyValueReader, key []byte) (*big.Int, error) {
72-
b, err := db.Get(key)
73-
if err != nil {
74-
return nil, err
75-
}
76-
return new(big.Int).SetBytes(b), nil
77-
}
78-
79-
func ParseBigInt(b []byte) (*big.Int, error) {
80-
return new(big.Int).SetBytes(b), nil
81-
}
82-
8370
func PutUInt32(db KeyValueWriter, key []byte, val uint32) error {
8471
b := PackUInt32(val)
8572
return db.Put(key, b)

avalanchego/genesis/genesis_coston.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ var (
8585
TxFeeConfig: TxFeeConfig{
8686
CreateAssetTxFee: 10 * units.MilliAvax,
8787
StaticFeeConfig: txfee.StaticConfig{
88-
TxFee: units.MilliAvax,
89-
CreateSubnetTxFee: 100 * units.MilliAvax,
90-
CreateBlockchainTxFee: 100 * units.MilliAvax,
91-
92-
TransformSubnetTxFee: 1 * units.Avax,
88+
TxFee: units.MilliAvax,
89+
CreateSubnetTxFee: 100 * units.MilliAvax,
90+
TransformSubnetTxFee: 100 * units.MilliAvax,
91+
CreateBlockchainTxFee: 100 * units.MilliAvax,
9392
AddPrimaryNetworkValidatorFee: 0,
9493
AddPrimaryNetworkDelegatorFee: 0,
9594
AddSubnetValidatorFee: units.MilliAvax,

avalanchego/genesis/genesis_costwo.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ var (
2222
TxFeeConfig: TxFeeConfig{
2323
CreateAssetTxFee: units.MilliAvax,
2424
StaticFeeConfig: txfee.StaticConfig{
25-
TxFee: units.MilliAvax,
26-
CreateSubnetTxFee: 100 * units.MegaAvax,
27-
CreateBlockchainTxFee: 100 * units.MegaAvax,
28-
29-
TransformSubnetTxFee: 1 * units.Avax,
25+
TxFee: units.MilliAvax,
26+
CreateSubnetTxFee: 100 * units.MilliAvax,
27+
TransformSubnetTxFee: 100 * units.MilliAvax,
28+
CreateBlockchainTxFee: 100 * units.MilliAvax,
3029
AddPrimaryNetworkValidatorFee: 0,
3130
AddPrimaryNetworkDelegatorFee: 0,
3231
AddSubnetValidatorFee: units.MilliAvax,

avalanchego/genesis/genesis_flare.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ var (
2222
TxFeeConfig: TxFeeConfig{
2323
CreateAssetTxFee: units.MilliAvax,
2424
StaticFeeConfig: txfee.StaticConfig{
25-
TxFee: units.MilliAvax,
26-
CreateSubnetTxFee: 100 * units.MegaAvax,
27-
CreateBlockchainTxFee: 100 * units.MegaAvax,
28-
29-
TransformSubnetTxFee: 1 * units.Avax,
25+
TxFee: units.MilliAvax,
26+
CreateSubnetTxFee: 100 * units.MilliAvax,
27+
TransformSubnetTxFee: 100 * units.MilliAvax,
28+
CreateBlockchainTxFee: 100 * units.MilliAvax,
3029
AddPrimaryNetworkValidatorFee: 0,
3130
AddPrimaryNetworkDelegatorFee: 0,
3231
AddSubnetValidatorFee: units.MilliAvax,

avalanchego/genesis/genesis_local.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ var (
9999
LocalParams = Params{
100100
TxFeeConfig: TxFeeConfig{
101101
CreateAssetTxFee: units.MilliAvax,
102+
// For reference only, fees are set via program arguments (defaults are below)
102103
StaticFeeConfig: txfee.StaticConfig{
103104
TxFee: units.MilliAvax,
104105
CreateSubnetTxFee: 100 * units.MilliAvax,

avalanchego/genesis/genesis_localFlare.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ var (
2121
LocalFlareParams = Params{
2222
TxFeeConfig: TxFeeConfig{
2323
CreateAssetTxFee: units.MilliAvax,
24+
// For reference only, fees are set via program arguments (defaults are below)
2425
StaticFeeConfig: txfee.StaticConfig{
25-
TxFee: units.MilliAvax,
26-
CreateSubnetTxFee: 100 * units.MegaAvax,
27-
CreateBlockchainTxFee: 100 * units.MegaAvax,
28-
29-
TransformSubnetTxFee: 1 * units.Avax,
26+
TxFee: units.MilliAvax,
27+
CreateSubnetTxFee: 100 * units.MilliAvax,
28+
TransformSubnetTxFee: 100 * units.MilliAvax,
29+
CreateBlockchainTxFee: 100 * units.MilliAvax,
3030
AddPrimaryNetworkValidatorFee: 0,
3131
AddPrimaryNetworkDelegatorFee: 0,
3232
AddSubnetValidatorFee: units.MilliAvax,

avalanchego/genesis/params.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ type Params struct {
5050
}
5151

5252
func GetTxFeeConfig(networkID uint32) TxFeeConfig {
53+
// TxFee configs are ommitted for LocalFlare and Local networks since they
54+
// are set from program arguments (getTxFeeConfig)
5355
switch networkID {
5456
case constants.MainnetID:
5557
return MainnetParams.TxFeeConfig
56-
case constants.LocalID:
57-
return LocalParams.TxFeeConfig
5858
case constants.FlareID:
5959
return FlareParams.TxFeeConfig
6060
case constants.CostwoID:
6161
return CostwoParams.TxFeeConfig
62-
case constants.LocalFlareID:
63-
return LocalFlareParams.TxFeeConfig
6462
case constants.SongbirdID:
6563
return SongbirdParams.TxFeeConfig
6664
case constants.CostonID:

avalanchego/snow/networking/tracker/targeter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package tracker
55

66
import (
7+
"math/big"
8+
79
"github.com/ava-labs/avalanchego/ids"
810
"github.com/ava-labs/avalanchego/snow/validators"
911
"github.com/ava-labs/avalanchego/utils/constants"
@@ -69,6 +71,10 @@ func (t *targeter) TargetUsage(nodeID ids.NodeID) float64 {
6971
}
7072

7173
totalWeight := t.vdrs.TotalWeight(constants.PrimaryNetworkID)
74+
if totalWeight.Cmp(big.NewInt(0)) == 0 {
75+
return baseAlloc
76+
}
77+
7278
totalWeightFloat, _ := totalWeight.Float64()
7379

7480
vdrAlloc := t.vdrAlloc * float64(weight) / totalWeightFloat

0 commit comments

Comments
 (0)