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 5, 2024
1 parent 61a224a commit b7c49b1
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 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
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202411191550_operatorAVSSplits/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package _202411191550_operatorAVSSplits

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"

"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
query := `
create table if not exists operator_avs_splits (
operator varchar not null,
Expand Down
3 changes: 2 additions & 1 deletion pkg/postgres/migrations/202411191708_operatorPISplits/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package _202411191708_operatorPISplits

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"

"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
query := `
create table if not exists operator_pi_splits (
operator varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package _202411221331_operatorAVSSplitSnapshots

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"

"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS operator_avs_split_snapshots (
operator varchar not null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package _202411221331_operatorPISplitSnapshots

import (
"database/sql"
"github.com/Layr-Labs/sidecar/internal/config"

"gorm.io/gorm"
)

type Migration struct {
}

func (m *Migration) Up(db *sql.DB, grm *gorm.DB) error {
func (m *Migration) Up(db *sql.DB, grm *gorm.DB, cfg *config.Config) error {
queries := []string{
`CREATE TABLE IF NOT EXISTS operator_pi_split_snapshots (
operator varchar not null,
Expand Down

0 comments on commit b7c49b1

Please sign in to comment.