Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Jan 9, 2025
1 parent 5640e87 commit 1ca88c6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
11 changes: 7 additions & 4 deletions pkg/eigenState/operatorAVSSplits/operatorAVSSplits.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ func (oas *OperatorAVSSplitModel) GenerateStateRoot(blockNumber uint64) ([]byte,
return nil, err
}

inputs := oas.sortValuesForMerkleTree(inserts)
inputs, err := oas.sortValuesForMerkleTree(inserts)
if err != nil {
return nil, err
}

if len(inputs) == 0 {
return nil, nil
Expand Down Expand Up @@ -272,7 +275,7 @@ func (oas *OperatorAVSSplitModel) formatMerkleLeafValue(
return fmt.Sprintf("%s_%s_%016x_%016x_%016x", operator, avs, activatedAt.Unix(), oldOperatorAVSSplitBips, newOperatorAVSSplitBips), nil
}

func (oas *OperatorAVSSplitModel) sortValuesForMerkleTree(splits []*OperatorAVSSplit) []*base.MerkleTreeInput {
func (oas *OperatorAVSSplitModel) sortValuesForMerkleTree(splits []*OperatorAVSSplit) ([]*base.MerkleTreeInput, error) {
inputs := make([]*base.MerkleTreeInput, 0)
for _, split := range splits {
slotID := base.NewSlotID(split.TransactionHash, split.LogIndex)
Expand All @@ -287,7 +290,7 @@ func (oas *OperatorAVSSplitModel) sortValuesForMerkleTree(splits []*OperatorAVSS
zap.Uint64("oldOperatorAVSSplitBips", split.OldOperatorAVSSplitBips),
zap.Uint64("newOperatorAVSSplitBips", split.NewOperatorAVSSplitBips),
)
continue
return nil, err
}
inputs = append(inputs, &base.MerkleTreeInput{
SlotID: slotID,
Expand All @@ -299,7 +302,7 @@ func (oas *OperatorAVSSplitModel) sortValuesForMerkleTree(splits []*OperatorAVSS
return strings.Compare(string(i.SlotID), string(j.SlotID))
})

return inputs
return inputs, nil
}

func (oas *OperatorAVSSplitModel) DeleteState(startBlockNumber uint64, endBlockNumber uint64) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,23 @@ func (odrs *OperatorDirectedRewardSubmissionsModel) GetModelName() string {
return "OperatorDirectedRewardSubmissionsModel"
}

func (odrs *OperatorDirectedRewardSubmissionsModel) NewSlotID(blockNumber uint64, transactionHash string, logIndex uint64, rewardHash string, strategyIndex uint64, operatorIndex uint64) types.SlotID {
if odrs.globalConfig.ChainIsOneOf(config.Chain_Holesky, config.Chain_Preprod) && blockNumber < 3118055 {
func (odrs *OperatorDirectedRewardSubmissionsModel) NewSlotID(
blockNumber uint64,
transactionHash string,
logIndex uint64,
rewardHash string,
strategyIndex uint64,
operatorIndex uint64,
) (types.SlotID, error) {
forks, err := odrs.globalConfig.GetModelForks()
if err != nil {
return "", err
}
if odrs.globalConfig.ChainIsOneOf(config.Chain_Holesky, config.Chain_Preprod) && blockNumber < forks[config.ModelFork_Austin] {
// This format was used on preprod and testnet for rewards-v2 before launching to mainnet
return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%d_%d", rewardHash, strategyIndex, operatorIndex))
return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%d_%d", rewardHash, strategyIndex, operatorIndex)), nil
}
return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%016x_%016x", rewardHash, strategyIndex, operatorIndex))
return base.NewSlotIDWithSuffix(transactionHash, logIndex, fmt.Sprintf("%s_%016x_%016x", rewardHash, strategyIndex, operatorIndex)), nil
}

type operatorDirectedRewardData struct {
Expand Down Expand Up @@ -182,7 +193,19 @@ func (odrs *OperatorDirectedRewardSubmissionsModel) GetStateTransitions() (types
}

for _, rewardSubmission := range rewardSubmissions {
slotId := odrs.NewSlotID(log.BlockNumber, rewardSubmission.TransactionHash, rewardSubmission.LogIndex, rewardSubmission.RewardHash, rewardSubmission.StrategyIndex, rewardSubmission.OperatorIndex)
slotId, err := odrs.NewSlotID(log.BlockNumber, rewardSubmission.TransactionHash, rewardSubmission.LogIndex, rewardSubmission.RewardHash, rewardSubmission.StrategyIndex, rewardSubmission.OperatorIndex)
if err != nil {
odrs.logger.Sugar().Errorw("Failed to create slot ID",
zap.Uint64("blockNumber", log.BlockNumber),
zap.String("transactionHash", log.TransactionHash),
zap.Uint64("logIndex", log.LogIndex),
zap.String("rewardHash", rewardSubmission.RewardHash),
zap.Uint64("strategyIndex", rewardSubmission.StrategyIndex),
zap.Uint64("operatorIndex", rewardSubmission.OperatorIndex),
zap.Error(err),
)
return nil, err
}

_, ok := odrs.stateAccumulator[log.BlockNumber][slotId]
if ok {
Expand Down Expand Up @@ -354,7 +377,19 @@ func (odrs *OperatorDirectedRewardSubmissionsModel) formatMerkleLeafValue(
func (odrs *OperatorDirectedRewardSubmissionsModel) sortValuesForMerkleTree(submissions []*OperatorDirectedRewardSubmission) ([]*base.MerkleTreeInput, error) {
inputs := make([]*base.MerkleTreeInput, 0)
for _, submission := range submissions {
slotID := odrs.NewSlotID(submission.BlockNumber, submission.TransactionHash, submission.LogIndex, submission.RewardHash, submission.StrategyIndex, submission.OperatorIndex)
slotID, err := odrs.NewSlotID(submission.BlockNumber, submission.TransactionHash, submission.LogIndex, submission.RewardHash, submission.StrategyIndex, submission.OperatorIndex)
if err != nil {
odrs.logger.Sugar().Errorw("Failed to create slot ID",
zap.Uint64("blockNumber", submission.BlockNumber),
zap.String("transactionHash", submission.TransactionHash),
zap.Uint64("logIndex", submission.LogIndex),
zap.String("rewardHash", submission.RewardHash),
zap.Uint64("strategyIndex", submission.StrategyIndex),
zap.Uint64("operatorIndex", submission.OperatorIndex),
zap.Error(err),
)
return nil, err
}

value, err := odrs.formatMerkleLeafValue(submission.BlockNumber, submission.RewardHash, submission.Strategy, submission.Multiplier, submission.Operator, submission.Amount)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions pkg/eigenState/operatorPISplits/operatorPISplits.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ func (ops *OperatorPISplitModel) GenerateStateRoot(blockNumber uint64) ([]byte,
return nil, err
}

inputs := ops.sortValuesForMerkleTree(inserts)
inputs, err := ops.sortValuesForMerkleTree(inserts)
if err != nil {
return nil, err
}

if len(inputs) == 0 {
return nil, nil
Expand Down Expand Up @@ -269,7 +272,7 @@ func (ops *OperatorPISplitModel) formatMerkleLeafValue(
return fmt.Sprintf("%s_%016x_%016x_%016x", operator, activatedAt.Unix(), oldOperatorPISplitBips, newOperatorPISplitBips), nil
}

func (ops *OperatorPISplitModel) sortValuesForMerkleTree(splits []*OperatorPISplit) []*base.MerkleTreeInput {
func (ops *OperatorPISplitModel) sortValuesForMerkleTree(splits []*OperatorPISplit) ([]*base.MerkleTreeInput, error) {
inputs := make([]*base.MerkleTreeInput, 0)
for _, split := range splits {
slotID := base.NewSlotID(split.TransactionHash, split.LogIndex)
Expand All @@ -283,7 +286,7 @@ func (ops *OperatorPISplitModel) sortValuesForMerkleTree(splits []*OperatorPISpl
zap.Uint64("oldOperatorPISplitBips", split.OldOperatorPISplitBips),
zap.Uint64("newOperatorPISplitBips", split.NewOperatorPISplitBips),
)
continue
return nil, err
}
inputs = append(inputs, &base.MerkleTreeInput{
SlotID: slotID,
Expand All @@ -295,7 +298,7 @@ func (ops *OperatorPISplitModel) sortValuesForMerkleTree(splits []*OperatorPISpl
return strings.Compare(string(i.SlotID), string(j.SlotID))
})

return inputs
return inputs, nil
}

func (ops *OperatorPISplitModel) DeleteState(startBlockNumber uint64, endBlockNumber uint64) error {
Expand Down

0 comments on commit 1ca88c6

Please sign in to comment.