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

[WIP] feat: add price oracle module #6

Closed
wants to merge 26 commits into from

Conversation

leonz789
Copy link
Contributor

@leonz789 leonz789 commented Feb 28, 2024

Description

This is currently a WIP pr to track the process, The code is undergoing rapid development, with the possibility of frequent and substantial changes.

task list:

  • basic framework of the module
  • state definition
  • aggregation logic
  • recache aggregation data from KVStore
  • client cli
  • uint test & integration test

This version has implemented logics and rules that are compatible with v2, so a hard fork might not be needed to upgrade to V2.

price oracle

Rationale

N/A

Example

N/A

Changes

N/A

var key []byte

tokenIdBytes := make([]byte, 4)
binary.BigEndian.PutUint32(tokenIdBytes, uint32(tokenId))

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion

func (p *params) getTokenFeeder(feederId int32) *types.TokenFeeder {
for k, v := range p.TokenFeeders {
if int32(k) == feederId {

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
)

var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion

Potential integer overflow by integer type conversion
package oracle

import (
"math/rand"

Check failure

Code scanning / gosec

Blocklisted import runtime

Blocklisted import math/rand

// 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.

Returned error is not propagated up the stack.

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))

Check warning

Code scanning / gosec

Errors unhandled.

Errors unhandled.
b := store.Get(types.PricesRoundKey(nextRoundId - 1))
if b != nil {
//should always be true
k.cdc.Unmarshal(b, &price)

Check warning

Code scanning / gosec

Errors unhandled.

Errors unhandled.
return
}

k.cdc.Unmarshal(b, &price)

Check warning

Code scanning / gosec

Errors unhandled.

Errors unhandled.
Comment on lines +441 to +455
for k := range m.Onchain {
v := m.Onchain[k]
baseI := i
i -= len(v)
copy(dAtA[i:], v)
i = encodeVarintInfo(dAtA, i, uint64(len(v)))
i--
dAtA[i] = 0x12
i = encodeVarintInfo(dAtA, i, uint64(k))
i--
dAtA[i] = 0x8
i = encodeVarintInfo(dAtA, i, uint64(baseI-i))
i--
dAtA[i] = 0x12
}

Check warning

Code scanning / CodeQL

Iteration over map

Iteration over map may be a possible source of non-determinism
Comment on lines +458 to +472
for k := range m.Offchain {
v := m.Offchain[k]
baseI := i
i -= len(v)
copy(dAtA[i:], v)
i = encodeVarintInfo(dAtA, i, uint64(len(v)))
i--
dAtA[i] = 0x12
i = encodeVarintInfo(dAtA, i, uint64(k))
i--
dAtA[i] = 0x8
i = encodeVarintInfo(dAtA, i, uint64(baseI-i))
i--
dAtA[i] = 0xa
}

Check warning

Code scanning / CodeQL

Iteration over map

Iteration over map may be a possible source of non-determinism
Comment on lines +600 to +605
for k, v := range m.Offchain {
_ = k
_ = v
mapEntrySize := 1 + sovInfo(uint64(k)) + 1 + len(v) + sovInfo(uint64(len(v)))
n += mapEntrySize + 1 + sovInfo(uint64(mapEntrySize))
}

Check warning

Code scanning / CodeQL

Iteration over map

Iteration over map may be a possible source of non-determinism
Comment on lines +608 to +613
for k, v := range m.Onchain {
_ = k
_ = v
mapEntrySize := 1 + sovInfo(uint64(k)) + 1 + len(v) + sovInfo(uint64(len(v)))
n += mapEntrySize + 1 + sovInfo(uint64(mapEntrySize))
}

Check warning

Code scanning / CodeQL

Iteration over map

Iteration over map may be a possible source of non-determinism
package nullify

import (
"reflect"

Check notice

Code scanning / CodeQL

Sensitive package import

Certain system packages contain functions which may be a possible source of non-determinism

import (
"reflect"
"unsafe"

Check notice

Code scanning / CodeQL

Sensitive package import

Certain system packages contain functions which may be a possible source of non-determinism
opWeightMsgCreatePrice,
defaultWeightMsgCreatePrice,
func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) sdk.Msg {
oraclesimulation.SimulateMsgCreatePrice(am.accountKeeper, am.bankKeeper, am.keeper)

Check warning

Code scanning / CodeQL

Expression has no effect

This expression has no effect.
@leonz789 leonz789 mentioned this pull request Apr 2, 2024
@leonz789 leonz789 closed this Apr 2, 2024
@leonz789 leonz789 mentioned this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant