Skip to content

Commit

Permalink
Merge pull request #5 from Layr-Labs/sm-calc
Browse files Browse the repository at this point in the history
Move state calculation logic out of sql for stakerDelegations
  • Loading branch information
seanmcgary authored Sep 6, 2024
2 parents d09a779 + 4163b83 commit c69ee15
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 152 deletions.
10 changes: 9 additions & 1 deletion internal/eigenState/avsOperators/avsOperators.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (a *AvsOperators) IsInterestingLog(log *storage.TransactionLog) bool {
return a.BaseEigenState.IsInterestingLog(addresses, log)
}

func (a *AvsOperators) StartBlockProcessing(blockNumber uint64) error {
return nil
}

// Handle the state change for the given log
//
// Takes a log and iterates over the state transitions to determine which state change to apply based on block number.
Expand Down Expand Up @@ -201,7 +205,7 @@ func (a *AvsOperators) writeStateChange(change *AvsOperatorChange) (*AvsOperator
// 4. Determine which rows from the previous block should be carried over and which shouldnt (i.e. deregistrations)
// 5. Geneate the final state by unioning the carryover and the new registrations
// 6. Insert the final state into the registered_avs_operators table
func (a *AvsOperators) WriteFinalState(blockNumber uint64) error {
func (a *AvsOperators) CommitFinalState(blockNumber uint64) error {
query := `
with new_changes as (
select
Expand Down Expand Up @@ -315,6 +319,10 @@ func (a *AvsOperators) getDifferenceInStates(blockNumber uint64) ([]RegisteredAv
return results, nil
}

func (a *AvsOperators) ClearAccumulatedState(blockNumber uint64) error {
panic("implement me")
}

// Generates a state root for the given block number.
//
// 1. Select all registered_avs_operators for the given block number ordered by avs and operator asc
Expand Down
4 changes: 2 additions & 2 deletions internal/eigenState/avsOperators/avsOperators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Test_AvsOperatorState(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, stateChange)

err = avsOperatorState.WriteFinalState(blockNumber)
err = avsOperatorState.CommitFinalState(blockNumber)
assert.Nil(t, err)

states := []RegisteredAvsOperators{}
Expand Down Expand Up @@ -170,7 +170,7 @@ func Test_AvsOperatorState(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, stateChange)

err = avsOperatorState.WriteFinalState(log.BlockNumber)
err = avsOperatorState.CommitFinalState(log.BlockNumber)
assert.Nil(t, err)

states := []RegisteredAvsOperators{}
Expand Down
10 changes: 9 additions & 1 deletion internal/eigenState/operatorShares/operatorShares.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (osm *OperatorSharesModel) IsInterestingLog(log *storage.TransactionLog) bo
return osm.BaseEigenState.IsInterestingLog(addresses, log)
}

func (osm *OperatorSharesModel) StartBlockProcessing(blockNumber uint64) error {
return nil
}

func (osm *OperatorSharesModel) HandleStateChange(log *storage.TransactionLog) (interface{}, error) {
stateChanges, sortedBlockNumbers := osm.GetStateTransitions()

Expand Down Expand Up @@ -189,7 +193,7 @@ func (osm *OperatorSharesModel) writeStateChange(change *OperatorShareChange) (i
return change, nil
}

func (osm *OperatorSharesModel) WriteFinalState(blockNumber uint64) error {
func (osm *OperatorSharesModel) CommitFinalState(blockNumber uint64) error {
query := `
with new_sum as (
select
Expand Down Expand Up @@ -281,6 +285,10 @@ func (osm *OperatorSharesModel) getDifferencesInStates(currentBlock uint64) ([]O
return diffs, nil
}

func (osm *OperatorSharesModel) ClearAccumulatedState(blockNumber uint64) error {
panic("implement me")
}

func (osm *OperatorSharesModel) GenerateStateRoot(blockNumber uint64) (types.StateRoot, error) {
diffs, err := osm.getDifferencesInStates(blockNumber)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/eigenState/operatorShares/operatorShares_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Test_OperatorSharesState(t *testing.T) {
assert.Nil(t, err)
assert.NotNil(t, stateChange)

err = model.WriteFinalState(blockNumber)
err = model.CommitFinalState(blockNumber)
assert.Nil(t, err)

states := []OperatorShares{}
Expand Down
Loading

0 comments on commit c69ee15

Please sign in to comment.