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

Index operator state by quorum id not quorum index #399

Merged
merged 2 commits into from
Mar 27, 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
8 changes: 4 additions & 4 deletions core/eth/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func NewChainState(tx core.Transactor, client common.EthClient) *ChainState {
var _ core.ChainState = (*ChainState)(nil)

func (cs *ChainState) GetOperatorStateByOperator(ctx context.Context, blockNumber uint, operator core.OperatorID) (*core.OperatorState, error) {
operatorsByQuorum, quorumIds, err := cs.Tx.GetOperatorStakes(ctx, operator, uint32(blockNumber))
operatorsByQuorum, _, err := cs.Tx.GetOperatorStakes(ctx, operator, uint32(blockNumber))
if err != nil {
return nil, err
}

return getOperatorState(operatorsByQuorum, quorumIds, uint32(blockNumber))
return getOperatorState(operatorsByQuorum, uint32(blockNumber))

}

Expand All @@ -38,7 +38,7 @@ func (cs *ChainState) GetOperatorState(ctx context.Context, blockNumber uint, qu
return nil, err
}

return getOperatorState(operatorsByQuorum, quorums, uint32(blockNumber))
return getOperatorState(operatorsByQuorum, uint32(blockNumber))
}

func (cs *ChainState) GetCurrentBlockNumber() (uint, error) {
Expand All @@ -51,7 +51,7 @@ func (cs *ChainState) GetCurrentBlockNumber() (uint, error) {
return uint(header.Number.Uint64()), nil
}

func getOperatorState(operatorsByQuorum core.OperatorStakes, quorumIds []core.QuorumID, blockNumber uint32) (*core.OperatorState, error) {
func getOperatorState(operatorsByQuorum core.OperatorStakes, blockNumber uint32) (*core.OperatorState, error) {
operators := make(map[core.QuorumID]map[core.OperatorID]*core.OperatorInfo)
totals := make(map[core.QuorumID]*core.OperatorInfo)

Expand Down
7 changes: 4 additions & 3 deletions core/eth/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,12 @@ func (t *Transactor) GetOperatorStakes(ctx context.Context, operator core.Operat
return nil, nil, err
}

// BitmapToQuorumIds returns an ordered list of quorums in ascending order, which is the same order as the state_ returned by the contract
quorumIds := BitmapToQuorumIds(quorumBitmap)

state := make(core.OperatorStakes, len(state_))
for i := range state_ {
quorumID := core.QuorumID(i)
quorumID := quorumIds[i]
Comment on lines +374 to +378
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're assuming BitmapToQuorumIds returned an ordered list of quorums in ascending order, and the quorums in state_ is in the same order, which is true in the current implementation.

state[quorumID] = make(map[core.OperatorIndex]core.OperatorStake, len(state_[i]))
for j, op := range state_[i] {
operatorIndex := core.OperatorIndex(j)
Expand All @@ -383,8 +386,6 @@ func (t *Transactor) GetOperatorStakes(ctx context.Context, operator core.Operat
}
}

quorumIds := BitmapToQuorumIds(quorumBitmap)

return state, quorumIds, nil
}

Expand Down
Loading