Skip to content

Commit d435267

Browse files
committed
fix: change the type of amount and vote to string for bigint represent
1 parent 5761cfb commit d435267

File tree

18 files changed

+499
-311
lines changed

18 files changed

+499
-311
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ vendor/
3838
*~
3939

4040
# Logs
41+
logs/*
4142
*.log
4243

44+
4345
# Temporary files
4446
*.tmp
4547
*.temp

cmd/dispatcher/aggregate.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/hex"
66
"fmt"
7+
"math/big"
78
"time"
89

910
"github.com/ethereum/go-ethereum/common"
@@ -46,17 +47,21 @@ func AggregateSignatures(validResponses map[string][]byte, req *config.Request,
4647
}
4748

4849
// Calculate total power
49-
var totalPower uint64 = 0
50+
var totalPower *big.Int = big.NewInt(0)
5051
for _, val := range valSetResp.ValidatorWithBlsKeys {
51-
totalPower += val.VotingPower
52+
power, ok := new(big.Int).SetString(val.VotingPower, 10)
53+
if !ok {
54+
return nil, fmt.Errorf("failed to parse voting power for validator %s: %s", val.ValidatorAddress, val.VotingPower)
55+
}
56+
totalPower.Add(totalPower, power)
5257
}
5358

5459
// Convert to types.ValidatorSet
5560
validatorSet := make(types.ValidatorSet, len(valSetResp.ValidatorWithBlsKeys))
5661
for i, val := range valSetResp.ValidatorWithBlsKeys {
5762
validatorSet[i] = types.Validator{
5863
Addr: common.HexToAddress(val.ValidatorAddress).Bytes(),
59-
Power: int64(val.VotingPower),
64+
Power: val.VotingPower,
6065
}
6166
}
6267

@@ -92,4 +97,4 @@ func AggregateSignatures(validResponses map[string][]byte, req *config.Request,
9297
}
9398

9499
return &ckptWithMeta, nil
95-
}
100+
}

cmd/dispatcher/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request, cfg *config.Dispatche
111111
currentEpoch := aggregatedCkpt.Ckpt.EpochNum
112112
interval := cfg.RewardDistrInterval
113113
if interval <= 0 {
114-
interval = 2 // Default to distributing two epoch
114+
interval = 10 // Default to distributing ten epochs
115115
}
116116

117117
if currentEpoch%uint64(interval) == 0 {

cmd/dispatcher/query.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"strconv"
87
"time"
98

109
"github.com/spf13/cobra"
@@ -144,7 +143,7 @@ func queryBlsKeys(cmd *cobra.Command, args []string) {
144143
fmt.Printf("Validator #%d:\n", i+1)
145144
fmt.Printf(" Address: %s\n", validator.ValidatorAddress)
146145
fmt.Printf(" BLS Public Key: %s\n", validator.BlsPubKeyHex)
147-
fmt.Printf(" Voting Power: %s\n", strconv.FormatUint(validator.VotingPower, 10))
146+
fmt.Printf(" Voting Power: %s\n", validator.VotingPower)
148147
fmt.Println("-----------------------------------")
149148
}
150149
}

cmd/dispatcher/report_eth.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ func ReportCheckpointToEthereum(aggregatedCkpt *types.RawCheckpointWithMeta, cfg
6868
// Convert checkpoint data for contract call
6969
epochNum := aggregatedCkpt.Ckpt.EpochNum
7070
blockHash := common.BytesToHash(*aggregatedCkpt.Ckpt.BlockHash)
71-
powerSum := aggregatedCkpt.PowerSum
71+
powerSum, ok := new(big.Int).SetString(aggregatedCkpt.PowerSum, 10)
72+
if !ok {
73+
return fmt.Errorf("failed to parse power sum: %s", aggregatedCkpt.PowerSum)
74+
}
7275

7376
var blsMultiSig []byte
7477
if aggregatedCkpt.Ckpt.BlsMultiSig != nil {

contracts/artifacts/CKPTValStaking.abi

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
},
8181
{
8282
"indexed": false,
83-
"internalType": "uint64",
83+
"internalType": "uint256",
8484
"name": "powerSum",
85-
"type": "uint64"
85+
"type": "uint256"
8686
}
8787
],
8888
"name": "CheckpointSubmitted",
@@ -314,6 +314,19 @@
314314
"name": "ValidatorUpdated",
315315
"type": "event"
316316
},
317+
{
318+
"inputs": [],
319+
"name": "CKPTRewardScalingFactor",
320+
"outputs": [
321+
{
322+
"internalType": "uint256",
323+
"name": "",
324+
"type": "uint256"
325+
}
326+
],
327+
"stateMutability": "view",
328+
"type": "function"
329+
},
317330
{
318331
"inputs": [],
319332
"name": "DEFAULT_ADMIN_ROLE",
@@ -448,9 +461,9 @@
448461
"type": "bytes"
449462
},
450463
{
451-
"internalType": "uint64",
464+
"internalType": "uint256",
452465
"name": "powerSum",
453-
"type": "uint64"
466+
"type": "uint256"
454467
}
455468
],
456469
"stateMutability": "view",
@@ -689,19 +702,6 @@
689702
"stateMutability": "nonpayable",
690703
"type": "function"
691704
},
692-
{
693-
"inputs": [],
694-
"name": "lockPeriod",
695-
"outputs": [
696-
{
697-
"internalType": "uint256",
698-
"name": "",
699-
"type": "uint256"
700-
}
701-
],
702-
"stateMutability": "view",
703-
"type": "function"
704-
},
705705
{
706706
"inputs": [],
707707
"name": "minimumStake",
@@ -830,7 +830,7 @@
830830
},
831831
{
832832
"inputs": [],
833-
"name": "rewardRate",
833+
"name": "rewardRateByLockTime",
834834
"outputs": [
835835
{
836836
"internalType": "uint256",
@@ -845,11 +845,11 @@
845845
"inputs": [
846846
{
847847
"internalType": "uint256",
848-
"name": "_lockPeriod",
848+
"name": "_CKPTRewardScalingFactor",
849849
"type": "uint256"
850850
}
851851
],
852-
"name": "setLockPeriod",
852+
"name": "setCKPTRewardScalingFactor",
853853
"outputs": [],
854854
"stateMutability": "nonpayable",
855855
"type": "function"
@@ -893,6 +893,19 @@
893893
"stateMutability": "nonpayable",
894894
"type": "function"
895895
},
896+
{
897+
"inputs": [
898+
{
899+
"internalType": "uint256",
900+
"name": "_lockPeriod",
901+
"type": "uint256"
902+
}
903+
],
904+
"name": "setUnstakeLockPeriod",
905+
"outputs": [],
906+
"stateMutability": "nonpayable",
907+
"type": "function"
908+
},
896909
{
897910
"inputs": [
898911
{
@@ -979,9 +992,9 @@
979992
"type": "bytes"
980993
},
981994
{
982-
"internalType": "uint64",
995+
"internalType": "uint256",
983996
"name": "_powerSum",
984-
"type": "uint64"
997+
"type": "uint256"
985998
}
986999
],
9871000
"name": "submitCheckpoint",
@@ -1021,6 +1034,19 @@
10211034
"stateMutability": "nonpayable",
10221035
"type": "function"
10231036
},
1037+
{
1038+
"inputs": [],
1039+
"name": "unstakeLockPeriod",
1040+
"outputs": [
1041+
{
1042+
"internalType": "uint256",
1043+
"name": "",
1044+
"type": "uint256"
1045+
}
1046+
],
1047+
"stateMutability": "view",
1048+
"type": "function"
1049+
},
10241050
{
10251051
"inputs": [
10261052
{
@@ -1125,4 +1151,4 @@
11251151
"stateMutability": "view",
11261152
"type": "function"
11271153
}
1128-
]
1154+
]

contracts/artifacts/CKPTValStaking.bin

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

contracts/ckpt_val_staking/CKPTValStaking.go

Lines changed: 133 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/config/dis_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"DBport": 5432,
44
"DBuser": "postgres",
55
"DBpassword": "hetu",
6-
"DBname": "bls_db",
6+
"DBname": "bls_db3",
77
"Httpport": 8080,
88
"Tcpport": 8081,
99
"EnableReport": true,
@@ -12,6 +12,6 @@
1212
"ChainID": "hetu_560002-1",
1313
"EthRpcURL": "http://localhost:8545",
1414
"EthChainID": 560002,
15-
"ValidatorStakingAddress": "0xAD3Eade0d03C3aE3265283FddA1292E24B93bD71",
15+
"ValidatorStakingAddress": "0x59FF9362DE95fcd19983677BcCB2f23062d2E14E",
1616
"RewardDistrInterval": 2
1717
}

docs/config/val_config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"DBpassword": "hetu",
66
"DBname": "validator_db",
77
"dispatchertcp": "localhost:8081",
8-
"ListenAddr": "192.168.1.2",
8+
"ListenAddr": "localhost",
99
"port": 0,
1010
"ChainRpcURL": "http://localhost:8545",
11-
"StakingTokenAddress": "0xCffc027B6C6B1c8E3d0568bAB038876ae22B491D",
12-
"ValidatorStakingAddress": "0xAD3Eade0d03C3aE3265283FddA1292E24B93bD71",
11+
"StakingTokenAddress": "0x98a4e8735E0F99a758a7Cd86b74BB7FA32EF9670",
12+
"ValidatorStakingAddress": "0x59FF9362DE95fcd19983677BcCB2f23062d2E14E",
1313
"DispatcherURL": "http://localhost:8080",
1414
"ChainGRpcURL": "localhost:9090",
1515
"CometBFTSvr": "localhost:26657",

0 commit comments

Comments
 (0)