From c03dcd10efbc81500e2dbca76c1abeda71f63158 Mon Sep 17 00:00:00 2001 From: Sean McGary Date: Thu, 5 Dec 2024 12:23:03 -0600 Subject: [PATCH] fix: backport stateroot generation fixes --- .../operatorAVSSplits/operatorAVSSplits.go | 16 +++++++--------- .../operatorAVSSplits/operatorAVSSplits_test.go | 2 +- .../operatorDirectedRewardSubmissions_test.go | 2 +- .../operatorPISplits/operatorPISplits.go | 16 +++++++--------- .../operatorPISplits/operatorPISplits_test.go | 2 +- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/pkg/eigenState/operatorAVSSplits/operatorAVSSplits.go b/pkg/eigenState/operatorAVSSplits/operatorAVSSplits.go index ddaa802a..cb1c2f30 100644 --- a/pkg/eigenState/operatorAVSSplits/operatorAVSSplits.go +++ b/pkg/eigenState/operatorAVSSplits/operatorAVSSplits.go @@ -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" @@ -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 { diff --git a/pkg/eigenState/operatorAVSSplits/operatorAVSSplits_test.go b/pkg/eigenState/operatorAVSSplits/operatorAVSSplits_test.go index f7dd2fe5..9e60db9d 100644 --- a/pkg/eigenState/operatorAVSSplits/operatorAVSSplits_test.go +++ b/pkg/eigenState/operatorAVSSplits/operatorAVSSplits_test.go @@ -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 } diff --git a/pkg/eigenState/operatorDirectedRewardSubmissions/operatorDirectedRewardSubmissions_test.go b/pkg/eigenState/operatorDirectedRewardSubmissions/operatorDirectedRewardSubmissions_test.go index 6081e2a4..03521787 100644 --- a/pkg/eigenState/operatorDirectedRewardSubmissions/operatorDirectedRewardSubmissions_test.go +++ b/pkg/eigenState/operatorDirectedRewardSubmissions/operatorDirectedRewardSubmissions_test.go @@ -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 } diff --git a/pkg/eigenState/operatorPISplits/operatorPISplits.go b/pkg/eigenState/operatorPISplits/operatorPISplits.go index baea18be..da147662 100644 --- a/pkg/eigenState/operatorPISplits/operatorPISplits.go +++ b/pkg/eigenState/operatorPISplits/operatorPISplits.go @@ -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" @@ -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 { diff --git a/pkg/eigenState/operatorPISplits/operatorPISplits_test.go b/pkg/eigenState/operatorPISplits/operatorPISplits_test.go index 97672bb9..acd1de4a 100644 --- a/pkg/eigenState/operatorPISplits/operatorPISplits_test.go +++ b/pkg/eigenState/operatorPISplits/operatorPISplits_test.go @@ -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 }