Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move state calculation logic out of sql for stakerDelegations #5

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading