Skip to content

Commit

Permalink
fix: backport stateroot generation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Dec 11, 2024
1 parent a7f43aa commit 92e934d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
16 changes: 7 additions & 9 deletions pkg/eigenState/operatorAVSSplits/operatorAVSSplits.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
"strings"
"time"

"github.com/Layr-Labs/sidecar/pkg/storage"
"github.com/Layr-Labs/sidecar/pkg/utils"

"github.com/Layr-Labs/sidecar/internal/config"
"github.com/Layr-Labs/sidecar/pkg/eigenState/base"
"github.com/Layr-Labs/sidecar/pkg/eigenState/stateManager"
"github.com/Layr-Labs/sidecar/pkg/eigenState/types"
"github.com/Layr-Labs/sidecar/pkg/storage"
"go.uber.org/zap"
"golang.org/x/xerrors"
"gorm.io/gorm"
Expand Down Expand Up @@ -231,28 +229,28 @@ func (oas *OperatorAVSSplitModel) CommitFinalState(blockNumber uint64) error {
}

// GenerateStateRoot generates the state root for the given block number using the results of the state changes.
func (oas *OperatorAVSSplitModel) GenerateStateRoot(blockNumber uint64) (types.StateRoot, error) {
func (oas *OperatorAVSSplitModel) GenerateStateRoot(blockNumber uint64) ([]byte, error) {
inserts, err := oas.prepareState(blockNumber)
if err != nil {
return "", err
return nil, err
}

inputs := oas.sortValuesForMerkleTree(inserts)

if len(inputs) == 0 {
return "", nil
return nil, nil
}

fullTree, err := oas.MerkleizeState(blockNumber, inputs)
fullTree, err := oas.MerkleizeEigenState(blockNumber, inputs)
if err != nil {
oas.logger.Sugar().Errorw("Failed to create merkle tree",
zap.Error(err),
zap.Uint64("blockNumber", blockNumber),
zap.Any("inputs", inputs),
)
return "", err
return nil, err
}
return types.StateRoot(utils.ConvertBytesToString(fullTree.Root())), nil
return fullTree.Root(), nil
}

func (oas *OperatorAVSSplitModel) sortValuesForMerkleTree(splits []*OperatorAVSSplit) []*base.MerkleTreeInput {
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/operatorAVSSplits/operatorAVSSplits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/eigenState/operatorPISplits/operatorPISplits.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
"strings"
"time"

"github.com/Layr-Labs/sidecar/pkg/storage"
"github.com/Layr-Labs/sidecar/pkg/utils"

"github.com/Layr-Labs/sidecar/internal/config"
"github.com/Layr-Labs/sidecar/pkg/eigenState/base"
"github.com/Layr-Labs/sidecar/pkg/eigenState/stateManager"
"github.com/Layr-Labs/sidecar/pkg/eigenState/types"
"github.com/Layr-Labs/sidecar/pkg/storage"
"go.uber.org/zap"
"golang.org/x/xerrors"
"gorm.io/gorm"
Expand Down Expand Up @@ -229,28 +227,28 @@ func (ops *OperatorPISplitModel) CommitFinalState(blockNumber uint64) error {
}

// GenerateStateRoot generates the state root for the given block number using the results of the state changes.
func (ops *OperatorPISplitModel) GenerateStateRoot(blockNumber uint64) (types.StateRoot, error) {
func (ops *OperatorPISplitModel) GenerateStateRoot(blockNumber uint64) ([]byte, error) {
inserts, err := ops.prepareState(blockNumber)
if err != nil {
return "", err
return nil, err
}

inputs := ops.sortValuesForMerkleTree(inserts)

if len(inputs) == 0 {
return "", nil
return nil, nil
}

fullTree, err := ops.MerkleizeState(blockNumber, inputs)
fullTree, err := ops.MerkleizeEigenState(blockNumber, inputs)
if err != nil {
ops.logger.Sugar().Errorw("Failed to create merkle tree",
zap.Error(err),
zap.Uint64("blockNumber", blockNumber),
zap.Any("inputs", inputs),
)
return "", err
return nil, err
}
return types.StateRoot(utils.ConvertBytesToString(fullTree.Root())), nil
return fullTree.Root(), nil
}

func (ops *OperatorPISplitModel) sortValuesForMerkleTree(splits []*OperatorPISplit) []*base.MerkleTreeInput {
Expand Down
2 changes: 1 addition & 1 deletion pkg/eigenState/operatorPISplits/operatorPISplits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func setup() (

l, _ := logger.NewLogger(&logger.LoggerConfig{Debug: true})

dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, l)
dbname, _, grm, err := postgres.GetTestPostgresDatabase(cfg.DatabaseConfig, cfg, l)
if err != nil {
return dbname, nil, nil, nil, err
}
Expand Down

0 comments on commit 92e934d

Please sign in to comment.