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

refactor(oracle): introduce FeederManager to replace aggregator and caches for transaction handling #275

Merged
merged 69 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
43ecd9c
use base64 of hash to emit nst-balance-change-event, don't reset inde…
leonz789 Dec 26, 2024
88c99e1
don't slash on oracle downtime
leonz789 Dec 27, 2024
c560735
use lowercase to compare nst prefix
leonz789 Dec 27, 2024
fdf3b9f
fix: update roundID in staker's balance list
leonz789 Dec 27, 2024
d4eb834
ref:feedermanager. todo:events, uts, aggregator-tally
leonz789 Jan 6, 2025
20c5db5
remove unused file
leonz789 Jan 6, 2025
ef1e689
fix:pepareround,logs. complete:round tally related functions,state co…
leonz789 Jan 8, 2025
941042f
feat: add recovery check in beginblock for devmode-build
leonz789 Jan 9, 2025
4748e0a
feat: update snapshot of feedermanager as state for checkTx mode
leonz789 Jan 9, 2025
0b10c4b
emit events in endblock for updated feeders
leonz789 Jan 9, 2025
40187bc
revert changes to GrowRoundID
leonz789 Jan 9, 2025
759ac26
add unit tests for aggregation
leonz789 Jan 9, 2025
dc87b89
add equal methods for recovery logic check
leonz789 Jan 9, 2025
db1f629
remove outdated aggregator
leonz789 Jan 10, 2025
d10aba5
add build tag devmode and corresponding beginblock for recovery check
leonz789 Jan 12, 2025
6a9a8e1
fix lint
leonz789 Jan 13, 2025
79c2d7a
fix lint
leonz789 Jan 13, 2025
b7f5aa1
revert localnodesh
leonz789 Jan 13, 2025
2c4f386
fix checking for overflow
leonz789 Jan 13, 2025
c99e9bc
move e2e out of ut-cover test from ci
leonz789 Jan 13, 2025
0038a41
separate test jobs
leonz789 Jan 13, 2025
323ba1f
fix map iteration, ref
leonz789 Jan 13, 2025
6a7b7fb
print log instead of panic in endBlock
leonz789 Jan 13, 2025
562abde
set expected height in query to get deterministic when do e2e oracle …
leonz789 Jan 13, 2025
a055007
fix lint
leonz789 Jan 13, 2025
c49e003
refactor
leonz789 Jan 14, 2025
8c3a508
documentation
leonz789 Jan 14, 2025
b0dded9
refactor
leonz789 Jan 14, 2025
325bb9c
add version to sync nst validatorlist, fix aggregation for multiple p…
leonz789 Jan 15, 2025
8f2ba31
test: wait one more block to make sure state is committed
leonz789 Jan 15, 2025
a01e0a5
remove slashing params for oracle downtime
leonz789 Jan 16, 2025
4f27d82
lint proto
leonz789 Jan 16, 2025
981b903
remove package cache, refactor
leonz789 Jan 17, 2025
73fbc2a
remove unnecessary condition check
leonz789 Jan 17, 2025
ffb4d84
use sorted keys for logs consistance
leonz789 Jan 17, 2025
85361ae
comments for types
leonz789 Jan 17, 2025
7694abe
refactor:remove unused code
leonz789 Jan 17, 2025
bbf7388
revert sorted keys and use map range directly for nonce remove, sort …
leonz789 Jan 17, 2025
78d9bd3
remove redundant init for validators in endblock, remove function dup…
leonz789 Jan 17, 2025
9932d5d
hanld quote behavior in deterministic order with sorted keys, add com…
leonz789 Jan 17, 2025
a33cd64
test: add an e2e case for quoting after delegation
leonz789 Jan 19, 2025
5fb4e94
refactor
leonz789 Jan 19, 2025
1e717f7
refactor
leonz789 Jan 20, 2025
cd62e66
refactor nil compare for Equals
leonz789 Jan 20, 2025
2274bc2
typo
leonz789 Jan 20, 2025
f5bf4c2
add e2e and ut cases, add copy algo for fchecktx
leonz789 Jan 22, 2025
8c7f985
refactor, typo
leonz789 Jan 22, 2025
39b4b82
fix nil compare
leonz789 Jan 22, 2025
33a0c00
refactor
leonz789 Jan 22, 2025
d24c701
remove commentted codes, refactor
leonz789 Jan 23, 2025
437e97b
use math.pow to calculate count
leonz789 Jan 23, 2025
0f8842e
regenerate swagger doc
leonz789 Jan 23, 2025
b1c2539
regenerate proto
leonz789 Jan 24, 2025
59899c0
typo: fix annatation
leonz789 Jan 26, 2025
a9b28e2
regenerate proto, swagger
leonz789 Jan 26, 2025
a40bd46
rebase
leonz789 Feb 6, 2025
5918a4e
ref, typo
leonz789 Feb 6, 2025
d9abacb
typo
leonz789 Feb 7, 2025
28b95a1
add Equals for aggAlgorithm
leonz789 Feb 8, 2025
946ffab
refactor, remove unused interface
leonz789 Feb 12, 2025
5c91022
refactor
leonz789 Feb 12, 2025
4737999
refactor remove unnecessary check
leonz789 Feb 12, 2025
e1496c1
Revert "refactor"
leonz789 Feb 12, 2025
099d263
comments
leonz789 Feb 12, 2025
7fbb47d
Revert "update docker dependency"
leonz789 Feb 13, 2025
e15f0b1
use big0 from ethereum/common
leonz789 Feb 14, 2025
f4f583f
skip querying version when error not nil
leonz789 Feb 18, 2025
b49bfaf
upgrade curl version
leonz789 Feb 18, 2025
5562c50
change exocore to imuachain in semgrep config
leonz789 Feb 19, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
steps:
- name: Permission issue fix
# semgrep for some reason sets the working directory to exocore/exocore
run: git config --global --add safe.directory /__w/exocore/exocore
run: git config --global --add safe.directory /__w/imuachain/imuachain
- uses: actions/checkout@v4
- name: Get Diff
uses: technote-space/get-diff-action@v6.1.2
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ jobs:
run: |
make test-unit-cover
if: env.GIT_DIFF
test-unit-e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.21'
check-latest: true
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6.1.2
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: Test e2e cases
run: |
make test-unit-e2e
if: env.GIT_DIFF
26 changes: 19 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ all: build

build-all: tools build lint test vulncheck

.PHONY: distclean clean build-all
.PHONY: distclean clean build-all build

###############################################################################
### makTools & Dependencies ###
Expand Down Expand Up @@ -305,23 +305,35 @@ test-all: test-unit test-race
# we want to include all unit tests in the subfolders (tests/e2e/*)
# We also want to exclude the testutil folder because it contains only
# helper functions for the tests.
PACKAGES_UNIT=$(shell go list ./... | grep -v '/tests/e2e$$' | grep -v 'testutil')
PACKAGES_UNIT=$(shell go list ./... | grep -v '/tests/e2e' | grep -v 'testutil')
PACKAGES_UNIT_E2E=$(shell go list ./... | grep '/tests/e2e')
TEST_PACKAGES=./...
TEST_TARGETS := test-unit test-unit-cover test-race
TEST_TARGETS := test-unit test-unit-cover test-race test-unit-e2e test-unit-cover-local test-unit-e2e-local

# Test runs-specific rules. To add a new test target, just add
# a new rule, customise ARGS or TEST_PACKAGES ad libitum, and
# append the new rule to the TEST_TARGETS list.
test-unit: ARGS=-timeout=15m -gcflags=all=-l
test-unit: ARGS=-timeout=15m -gcflags=all=-l --tags devmode
test-unit: TEST_PACKAGES=$(PACKAGES_UNIT)

test-race: ARGS=-race
test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION)
$(TEST_TARGETS): run-tests

test-unit-cover: ARGS=-timeout=15m -coverprofile=cover.out -covermode=atomic -gcflags=all=-l
test-unit-cover: ARGS=-timeout=15m -coverprofile=cover.out -covermode=atomic -gcflags=all=-l --tags devmode
test-unit-cover: TEST_PACKAGES=$(PACKAGES_UNIT)

test-unit-e2e: ARGS=-timeout=15m --tags devmode
test-unit-e2e: TEST_PACKAGES=$(PACKAGES_UNIT_E2E)

test-unit-cover-local: ARGS=-timeout=30m -coverprofile=cover.out -covermode=atomic -gcflags=all=-l --tags 'devmode local'
test-unit-cover-local: TEST_PACKAGES=$(PACKAGES_UNIT)

test-unit-e2e-local: TEST_OPTION=local
test-unit-e2e-local: ARGS=-timeout=30m --tags devmode
test-unit-e2e-local: TEST_PACKAGES=$(PACKAGES_UNIT_E2E)


test-e2e:
@if [ -z "$(TARGET_VERSION)" ]; then \
echo "Building docker image from local codebase"; \
Expand All @@ -335,9 +347,9 @@ test-e2e:

run-tests:
ifneq (,$(shell which tparse 2>/dev/null))
go test -mod=readonly -json $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) | tparse
TEST_OPTION=$(TEST_OPTION) go test -mod=readonly -json $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) | tparse
else
go test -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES)
TEST_OPTION=$(TEST_OPTION) go test -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES)
endif

test-import:
Expand Down
3 changes: 3 additions & 0 deletions app/ante/cosmos/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ func (isd IncrementSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
msg := msg.(*oracletypes.MsgCreatePrice)
if accAddress, err := sdk.AccAddressFromBech32(msg.Creator); err != nil {
return ctx, errors.New("invalid address")
// #nosec G115 // safe conversion
// TODO: define msg.Nonce as uint32 to avoid conversion
} else if _, err := isd.oracleKeeper.CheckAndIncreaseNonce(ctx, sdk.ConsAddress(accAddress).String(), msg.FeederID, uint32(msg.Nonce)); err != nil {
return ctx, err
}
Expand Down Expand Up @@ -445,6 +447,7 @@ func (vscd ValidateSigCountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
sigCount := 0
for _, pk := range pubKeys {
sigCount += CountSubKeys(pk)
// #nosec G115
if uint64(sigCount) > params.TxSigLimit {
return ctx, sdkerrors.ErrTooManySignatures.Wrapf("signatures: %d, limit: %d", sigCount, params.TxSigLimit)
}
Expand Down
2 changes: 2 additions & 0 deletions app/ante/cosmos/txsize_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
}

// use stdsignature to mock the size of a full signature
// #nosec G115
simSig := legacytx.StdSignature{ // nolint:staticcheck // this will be removed when proto is ready
Signature: simSecp256k1Sig[:],
PubKey: pubkey,
}

sigBz := legacy.Cdc.MustMarshal(simSig)
// #nosec G115
cost := sdk.Gas(len(sigBz) + 6)

// If the pubkey is a multi-signature pubkey, then we estimate for the maximum
Expand Down
20 changes: 11 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,17 @@ func NewExocoreApp(
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, // to upgrade the chain
capabilitytypes.ModuleName, // before any module with capabilities like IBC
epochstypes.ModuleName, // to update the epoch
feemarkettypes.ModuleName, // set EIP-1559 gas prices
evmtypes.ModuleName, // stores chain id in memory
slashingtypes.ModuleName, // TODO after reward
evidencetypes.ModuleName, // TODO after reward
stakingtypes.ModuleName, // track historical info
ibcexported.ModuleName, // handles upgrades of chain and hence client
authz.ModuleName, // clear expired approvals
// beginblock of oracle will fill params cache, need to be put before epochs will use the params
// it need to put before other modules to fill params cahce before access
oracleTypes.ModuleName,
epochstypes.ModuleName, // to update the epoch
feemarkettypes.ModuleName, // set EIP-1559 gas prices
evmtypes.ModuleName, // stores chain id in memory
slashingtypes.ModuleName, // TODO after reward
evidencetypes.ModuleName, // TODO after reward
stakingtypes.ModuleName, // track historical info
ibcexported.ModuleName, // handles upgrades of chain and hence client
authz.ModuleName, // clear expired approvals
// no-op modules
ibctransfertypes.ModuleName,
icatypes.ModuleName,
Expand All @@ -944,7 +947,6 @@ func NewExocoreApp(
rewardTypes.ModuleName,
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
oracleTypes.ModuleName,
distrtypes.ModuleName,
)

Expand Down
75 changes: 30 additions & 45 deletions client/docs/swagger-ui/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -18574,11 +18574,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down Expand Up @@ -19321,11 +19316,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down Expand Up @@ -19693,11 +19683,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down Expand Up @@ -19774,6 +19759,11 @@
"schema": {
"type": "object",
"properties": {
"version": {
"type": "string",
"format": "int64",
"title": "version of the staker validator list changes"
},
"staker_info": {
"title": "all staker infos under the specified asset",
"type": "object",
Expand Down Expand Up @@ -19907,6 +19897,11 @@
"schema": {
"type": "object",
"properties": {
"version": {
"type": "string",
"format": "int64",
"title": "version of the staker validator list changes"
},
"staker_infos": {
"type": "array",
"items": {
Expand Down Expand Up @@ -20091,6 +20086,11 @@
"schema": {
"type": "object",
"properties": {
"version": {
"type": "string",
"format": "int64",
"title": "version of the staker validator list changes"
},
"staker_list": {
"title": "staker list including all stakers of request asset",
"type": "object",
Expand Down Expand Up @@ -41249,11 +41249,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down Expand Up @@ -41747,11 +41742,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down Expand Up @@ -42234,11 +42224,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down Expand Up @@ -42509,11 +42494,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand All @@ -42529,6 +42509,11 @@
"exocore.oracle.v1.QueryStakerInfoResponse": {
"type": "object",
"properties": {
"version": {
"type": "string",
"format": "int64",
"title": "version of the staker validator list changes"
},
"staker_info": {
"title": "all staker infos under the specified asset",
"type": "object",
Expand Down Expand Up @@ -42599,6 +42584,11 @@
"exocore.oracle.v1.QueryStakerInfosResponse": {
"type": "object",
"properties": {
"version": {
"type": "string",
"format": "int64",
"title": "version of the staker validator list changes"
},
"staker_infos": {
"type": "array",
"items": {
Expand Down Expand Up @@ -42689,6 +42679,11 @@
"exocore.oracle.v1.QueryStakerListResponse": {
"type": "object",
"properties": {
"version": {
"type": "string",
"format": "int64",
"title": "version of the staker validator list changes"
},
"staker_list": {
"title": "staker list including all stakers of request asset",
"type": "object",
Expand Down Expand Up @@ -43048,11 +43043,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down Expand Up @@ -43120,11 +43110,6 @@
"type": "string",
"title": "oracle_malicious_jail_duration defines the duratin one validator should be jailed for malicious behavior"
},
"slash_fraction_miss": {
"type": "string",
"format": "byte",
"title": "slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price"
},
"slash_fraction_malicious": {
"type": "string",
"format": "byte",
Expand Down
2 changes: 2 additions & 0 deletions precompiles/avs/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ func (p Precompile) EmitTaskSubmittedByOperator(ctx sdk.Context, stateDB vm.Stat
}
// Prepare the event data:sender,TaskResponse, BlsSignature, Phase
arguments := abi.Arguments{event.Inputs[2], event.Inputs[3], event.Inputs[4], event.Inputs[5]}
// #nosec G115
// TODO: consider modify define of Phase to uint8
packed, err := arguments.Pack(params.CallerAddress.String(), params.TaskResponse, params.BlsSignature, uint8(params.Phase))
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion precompiles/delegation/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (p Precompile) Delegate(
if err != nil {
return nil, err
}

err = p.delegationKeeper.DelegateTo(ctx, delegationParams)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions proto/exocore/oracle/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ message StakerInfosAssets {
string asset_id = 1;
// stakerInfos
repeated StakerInfo staker_infos = 2;
// nst_version is the version of nst to track validator list changes
int64 nst_version = 3;
}

// stakerListAssets bond stakerList to their related assets id
Expand All @@ -63,6 +65,8 @@ message StakerListAssets {
string asset_id = 1;
// stakerList
StakerList staker_list = 2;
// nst_version is the version of nst to track validator list changes
int64 nst_version = 3;
}

// ValidatorMissedRounds record missed rounds indexes for a validator which consAddr corresponding to the address
Expand Down
8 changes: 1 addition & 7 deletions proto/exocore/oracle/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}

// slashing related params
message SlashingParams {

Check failure on line 53 in proto/exocore/oracle/v1/params.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present field "6" with name "slash_fraction_malicious" on message "SlashingParams" was deleted.
// reported_rounds_window defines how many rounds included in one window for performance review of missing report
int64 reported_rounds_window = 1;
// min_reported_perwindow defines at least how many rounds should be reported, this is a percentage of window
Expand All @@ -71,14 +71,8 @@
(amino.dont_omitempty) = true,
(gogoproto.stdduration) = true
];
// slash_fraction_miss defines the fraction one validator should be punished for msissing reporting price
bytes slash_fraction_miss = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
// slash_fraction_malicious defines the fraction one validator should be punished for malicious behavior
bytes slash_fraction_malicious = 6 [
bytes slash_fraction_malicious = 5 [

Check failure on line 75 in proto/exocore/oracle/v1/params.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "5" with name "slash_fraction_malicious" on message "SlashingParams" changed option "json_name" from "slashFractionMiss" to "slashFractionMalicious".

Check failure on line 75 in proto/exocore/oracle/v1/params.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "5" on message "SlashingParams" changed name from "slash_fraction_miss" to "slash_fraction_malicious".
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
Expand Down
Loading
Loading