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

fix: convert hexString to IntString when add validator for stakers #19

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/feeder_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func RunPriceFeeder(conf *feedertypes.Config, logger feedertypes.LoggerInf, mnem
logger.Error("failed to reset all staker's validators for native-restaking-eth")
// TODO: should we just clear all info to prevent further nst update
}
} else {
logger.Info("updated Staker validator list for beaconchain fetcher", "stakerID", e.StakerID(), "validatorIndex", e.ValidatorIndex(), "deposit", e.Deposit(), "index", e.Index())
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions fetcher/beaconchain/beaconchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ func ResetStakerValidators(stakerInfos []*oracletypes.StakerInfo, all bool) erro
return defaultStakerValidators.reset(stakerInfos, all)
}
func UpdateStakerValidators(stakerIdx int, validatorIndexHex string, index uint64, deposit bool) bool {
validatorIndexInt, err := convertHexToIntStr(validatorIndexHex)
if err != nil {
logger.Error("failed to parse validatorIndexHex to intString")
return false
}
if deposit {
return defaultStakerValidators.addVIdx(stakerIdx, validatorIndexHex, index)
return defaultStakerValidators.addVIdx(stakerIdx, validatorIndexInt, index)
}
return defaultStakerValidators.removeVIdx(stakerIdx, validatorIndexHex, index)
return defaultStakerValidators.removeVIdx(stakerIdx, validatorIndexInt, index)
}

func (s *source) fetch(token string) (*types.PriceInfo, error) {
Expand Down Expand Up @@ -139,7 +144,6 @@ func (s *source) fetch(token string) (*types.PriceInfo, error) {
}
}

// validatorBalances, err := GetValidators(validatorIdxs, epoch)
validatorBalances, err := getValidators(vList.validators[i:], stateRoot)
if err != nil {
return nil, fmt.Errorf("failed to get validators from beaconchain, error:%w", err)
Expand All @@ -148,12 +152,12 @@ func (s *source) fetch(token string) (*types.PriceInfo, error) {
// this should be initialized from exocored
stakerBalance += int(validatorBalance[1])
}
if delta := stakerBalance - defaultBalance*len(vList.validators); delta != 0 {
if delta < maxChange {
delta = maxChange
if delta := stakerBalance - defaultBalance*l; delta != 0 {
if delta < maxChange*l {
delta = maxChange * l
}
stakerChanges = append(stakerChanges, []int{stakerIdx, delta})
s.logger.Info("fetched efb from beaconchain", "staker_index", stakerIdx, "balance_change", delta)
s.logger.Info("fetched efb from beaconchain", "staker_index", stakerIdx, "balance_change", delta, "validators_count", l)
hasEFBChanged = true
}
}
Expand Down
16 changes: 12 additions & 4 deletions fetcher/beaconchain/beaconchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import (
)

func TestGetEpoch(t *testing.T) {
vidxStr, err := convertHexToIntStr("0x00000000000000000000000000000000000000000000000000000000001CDD66")
if err != nil {
panic(err)
}
// GetValidators([]string{"1", "5", "9"}, 0)
validators := []string{
// "0xa1d1ad0714035353258038e964ae9675dc0252ee22cea896825c01458e1807bfad2f9969338798548d9858a571f7425c",
// "0xb2ff4716ed345b05dd1dfc6a5a9fa70856d8c75dcc9e881dd2f766d5f891326f0d10e96f3a444ce6c912b69c22c6754d",
"1",
"5",
"9",
// "1",
// "5",
// "9",
vidxStr,
}
urlEndpoint, _ = url.Parse("https://rpc.ankr.com/premium-http/eth_beacon/a5d2626c4027e6d924c870d2558bc774bc995ce917a17a654a92856b3279a586")
urlEndpoint, _ = url.Parse("https://rpc.ankr.com/premium-http/eth_beacon/a5d2626154027e423423d924c870d2558bc774bc995ce917a17a654a92856b1119a586")
slotsPerEpoch = 32

_, stateRoot, _ := getFinalizedEpoch()

//GetValidatorsAnkr([]string{"0xa1d1ad0714035353258038e964ae9675dc0252ee22cea896825c01458e1807bfad2f9969338798548d9858a571f7425c"}, stateRoot)
//GetValidatorsAnkr([]string{"0xb2ff4716ed345b05dd1dfc6a5a9fa70856d8c75dcc9e881dd2f766d5f891326f0d10e96f3a444ce6c912b69c22c6754d"}, stateRoot)
getValidators(validators, stateRoot)
Expand Down
Loading