-
Notifications
You must be signed in to change notification settings - Fork 10
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
[R4R] feat(oracle) #30
[R4R] feat(oracle) #30
Conversation
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.
gosec found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
ref: #24 |
|
||
b := store.Get(types.PricesRoundKey(roundId)) | ||
if b == nil { | ||
return |
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.
return uninitialized variables
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.
expected, found will be initialized to false by default, just return the false is expected.
Thanks @bwhour and @MaxMustermann2 for the pr review(#24 ), here's former comments i just copied here and corresponding replies:
Others:
|
6ebdc14
to
ede2652
Compare
|
||
// String implements the Stringer interface. | ||
func (p Params) String() string { | ||
out, _ := yaml.Marshal(p) |
Check warning
Code scanning / gosec
Returned error is not propagated up the stack. Warning
if len(validatorUpdates) > 0 { | ||
validatorList := make(map[string]*big.Int) | ||
for _, vu := range validatorUpdates { | ||
pubKey, _ := cryptocodec.FromTmProtoPublicKey(vu.PubKey) |
Check warning
Code scanning / gosec
Returned error is not propagated up the stack. Warning
|
||
// GetSigners returns the expected signers for a MsgUpdateParams message | ||
func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { | ||
addr, _ := sdk.AccAddressFromBech32(msg.Authority) |
Check warning
Code scanning / gosec
Returned error is not propagated up the stack. Warning
agc.FillPrice(&types.MsgCreatePrice{ | ||
Creator: msg.Validator, | ||
FeederID: msg.FeederID, | ||
Prices: msg.PSources, | ||
}) |
Check warning
Code scanning / gosec
Errors unhandled. Warning
For the workflow: Tests / test-unit-cover (pull_request) |
… scalffold dependencies
ed1e350
to
dc84085
Compare
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.
There is a lot of code in this PR, so didn't review it very deeply, just left some questions.
proto/exocore/oracle/genesis.proto
Outdated
|
||
//TODO: userDefinedTokenFeeder | ||
// latest block on which the validator set be updated | ||
ValidatorUpdateBlock validator_update_block = 4; |
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.
Should this start from 3?
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.
corrected
for feederID, round := range agc.rounds { | ||
if round.status == 1 { | ||
feeder := agc.params.GetTokenFeeder(feederID) | ||
// TODO: for mode=1, we don't do aggregate() here, since if it donesn't success in the transaction execution stage, it won't success here | ||
// but it's not always the same for other modes, switch modes | ||
switch common.Mode { | ||
case 1: | ||
expired := feeder.EndBlock > 0 && uint64(ctx.BlockHeight()) >= feeder.EndBlock | ||
outOfWindow := uint64(ctx.BlockHeight())-round.basedBlock >= uint64(common.MaxNonce) | ||
if expired || outOfWindow || force { | ||
failed = append(failed, feeder.TokenID) | ||
if expired { | ||
delete(agc.rounds, feederID) | ||
delete(agc.aggregators, feederID) | ||
} else { | ||
round.status = 2 | ||
agc.aggregators[feederID] = nil | ||
} | ||
} | ||
default: | ||
ctx.Logger().Info("mode other than 1 is not support now") | ||
} | ||
} | ||
// all status: 1->2, remove its aggregator | ||
if agc.aggregators[feederID] != nil && agc.aggregators[feederID].sealed { | ||
agc.aggregators[feederID] = nil | ||
} | ||
} |
Check warning
Code scanning / CodeQL
Iteration over map Warning
app/app.go
Outdated
@@ -448,15 +455,12 @@ func NewExocoreApp( | |||
operatorTypes.StoreKey, | |||
avsManagerTypes.StoreKey, | |||
avsTaskTypes.StoreKey, | |||
oracleTypes.StoreKey, | |||
) | |||
|
|||
// Add the EVM transient store key |
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.
Update or remove this comment.
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.
updated
@@ -977,6 +985,7 @@ func NewExocoreApp( | |||
withdrawTypes.ModuleName, | |||
rewardTypes.ModuleName, | |||
exoslashTypes.ModuleName, | |||
oracleTypes.ModuleName, |
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.
Please explain the rationale for these orders, if there is any. Or add a comment anyway if there is no particular rationale.
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.
updated
// nolint: staticcheck | ||
WithKeyTable(evmtypes.ParamKeyTable()) | ||
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint:staticcheck | ||
paramsKeeper.Subspace(oracleTypes.ModuleName).WithKeyTable(oracleTypes.ParamKeyTable()) |
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.
Shouldn't this also have the same nolint
line ?
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.
udpated
proto/exocore/oracle/price.proto
Outdated
int32 decimal = 2; | ||
// timestamp when the price corresponding to | ||
string timestamp = 3; | ||
// det_id is used for deterministic source to tell of which round from this soure the price is corresponded |
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.
typo: soure
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.
corrected
_ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway" | ||
_ "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger" | ||
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2" | ||
) |
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.
Nice!
return s.size | ||
} | ||
|
||
func NewSet[T comparable](length int) *Set[T] { |
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.
Nice!
} | ||
|
||
// RemovePrices removes a prices from the store | ||
func (k Keeper) RemovePrices( |
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 do some pruning of this data if it gets old ?
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.
Yes, we can add the pruning feature as config in further PR.
return nil, status.Error(codes.NotFound, "not found") | ||
} | ||
|
||
return &types.QueryGetPricesResponse{Prices: val}, nil |
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.
paginate ?
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.
Yes, i will update in a new PR with related test
@@ -0,0 +1,77 @@ | |||
package keeper |
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.
When is the data used? Can you explain briefly?
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.
This is used for refill the cache which stores price messages for aggregation:
since we have a window of more than one block to collect the prices from all validators, if this process is interrupted before the final aggregated price written to block, we would like to have some way to retrieve these messages. After we got the final price, the messages could be able to remove, so we just need the recent messages within the window.
@@ -0,0 +1,76 @@ | |||
package keeper |
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.
When is the data used? Can you explain briefly?
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.
This is like the recent_msgs, which is used to refill the cache:
the aggregation is affected by 3 elements:
- validatorset(:
votingPower
) - params(:
tokenFeeder
) - messages (: including price_with_
votingPower
fortokenFeeder
)
So when we do the refill, we just use these 3 data to reproduce the aggregation process.
But i think the recent_params could be optimized with carefully check like validator_update_block so that we don't need to keep the history params, currently this is a straightforward way. I will update in a new PR
x/oracle/keeper/single.go
Outdated
validatorPowers := make(map[string]*big.Int) | ||
k.IterateBondedValidatorsByPower(ctx, func(_ int64, validator stakingtypes.ValidatorI) bool { | ||
power := big.NewInt(validator.GetConsensusPower(validator.GetBondedTokens())) | ||
// addr := string(validator.GetOperator()) |
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.
Delete unnecessary comment
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.
updated
|
||
// SetRecentParams set a specific recentParams in the store from its index | ||
func (k Keeper) SetRecentParams(ctx sdk.Context, recentParams types.RecentParams) { | ||
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.RecentParamsKeyPrefix)) |
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.
Is this only used in genesis initialize?
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.
No, this is used to refill the cache
) | ||
|
||
// CreatePrice proposes price for new round of specific tokenFeeder | ||
func (ms msgServer) CreatePrice(goCtx context.Context, msg *types.MsgCreatePrice) (*types.MsgCreatePriceResponse, error) { |
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.
Wouldn't this be called by validator?
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.
This serves a a message service, and the message should be signed by validator
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.
fix the action error then
Description
Oracle module is used to collect external prices from sources(offchain/onchain) outside of exocorechain. And the prices access served by oracle module will be used by other modules like operator for voting power calculation.
Supersedes #6 , reconstruct the commits for easy to review.
commits: