-
Notifications
You must be signed in to change notification settings - Fork 191
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
feat: relax indexedChainState to ChainState for retrieval #943
base: master
Are you sure you want to change the base?
Changes from 1 commit
59b7ff7
1af099c
8b4969c
c99a079
47d242d
7351502
36b9280
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,14 @@ func (cs *ChainState) GetOperatorStateByOperator(ctx context.Context, blockNumbe | |
return nil, err | ||
} | ||
|
||
return getOperatorState(operatorsByQuorum, uint32(blockNumber)) | ||
socketMap := make(map[core.OperatorID]string) | ||
socket, err := cs.Tx.GetOperatorSocket(ctx, operator) | ||
if err != nil { | ||
return nil, err | ||
} | ||
socketMap[operator] = socket | ||
|
||
return getOperatorState(operatorsByQuorum, uint32(blockNumber), socketMap) | ||
|
||
} | ||
|
||
|
@@ -38,7 +45,12 @@ func (cs *ChainState) GetOperatorState(ctx context.Context, blockNumber uint, qu | |
return nil, err | ||
} | ||
|
||
return getOperatorState(operatorsByQuorum, uint32(blockNumber)) | ||
socketMap, err := cs.buildSocketMap(ctx, operatorsByQuorum) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this mean whenever we call this method, it will query the chain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes I expect this too. I can add socket map to the ChainState cache and only query if the operator is missing from the socket map. Although, that means we might need to add a refresh or a failover somewhere so that we don't use the old socket addresses after operators make an updater. Lmk what you think |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return getOperatorState(operatorsByQuorum, uint32(blockNumber), socketMap) | ||
} | ||
|
||
func (cs *ChainState) GetCurrentBlockNumber() (uint, error) { | ||
|
@@ -59,7 +71,26 @@ func (cs *ChainState) GetOperatorSocket(ctx context.Context, blockNumber uint, o | |
return socket, nil | ||
} | ||
|
||
func getOperatorState(operatorsByQuorum core.OperatorStakes, blockNumber uint32) (*core.OperatorState, error) { | ||
// buildSocketMap returns a map from operatorID to socket address for the operators in the operatorsByQuorum | ||
func (cs *ChainState) buildSocketMap(ctx context.Context, operatorsByQuorum core.OperatorStakes) (map[core.OperatorID]string, error) { | ||
socketMap := make(map[core.OperatorID]string) | ||
for _, quorum := range operatorsByQuorum { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't the key the quorum and the value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes exactly. This loop is to get all the operator ID and their socket from all quorums There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one way to address this would be to preload cache initially by querying every single operator in the current block. Then for the following requests, query the current set of operators, query the logs by filtering on |
||
for _, op := range quorum { | ||
// if the socket is already in the map, skip | ||
if _, ok := socketMap[op.OperatorID]; ok { | ||
continue | ||
} | ||
socket, err := cs.Tx.GetOperatorSocket(ctx, op.OperatorID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
socketMap[op.OperatorID] = socket | ||
} | ||
} | ||
return socketMap, nil | ||
} | ||
|
||
func getOperatorState(operatorsByQuorum core.OperatorStakes, blockNumber uint32, socketMap map[core.OperatorID]string) (*core.OperatorState, error) { | ||
operators := make(map[core.QuorumID]map[core.OperatorID]*core.OperatorInfo) | ||
totals := make(map[core.QuorumID]*core.OperatorInfo) | ||
|
||
|
@@ -69,15 +100,18 @@ func getOperatorState(operatorsByQuorum core.OperatorStakes, blockNumber uint32) | |
|
||
for ind, op := range quorum { | ||
operators[quorumID][op.OperatorID] = &core.OperatorInfo{ | ||
Stake: op.Stake, | ||
Index: core.OperatorIndex(ind), | ||
Stake: op.Stake, | ||
Index: core.OperatorIndex(ind), | ||
Socket: socketMap[op.OperatorID], | ||
} | ||
totalStake.Add(totalStake, op.Stake) | ||
} | ||
|
||
totals[quorumID] = &core.OperatorInfo{ | ||
Stake: totalStake, | ||
Index: core.OperatorIndex(len(quorum)), | ||
// no socket for the total | ||
Socket: "", | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move these methods to eth reader and remove this struct?
Not sure why we need a separate struct for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're caching the operator sockets, maybe we should keep this struct separate