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

feat(pricing): Add taxable did & resource messages, supply deflation, block rewards & simapp tests #392

Merged
merged 516 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
516 commits
Select commit Hold shift + click to select a range
a4c4e0e
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
askolesov Nov 22, 2022
58559e0
Merge branch 'did-normalization' into migration-tests
askolesov Nov 22, 2022
592f9c1
Raise of InitBlock order of execution
Eengineer1 Nov 22, 2022
455e532
Bump to include upstream AppHash fix
Eengineer1 Nov 22, 2022
49ef780
Raised order of InitGenesis
Eengineer1 Nov 22, 2022
2d31a11
Debugging
Eengineer1 Nov 22, 2022
0776647
Debugging v2
Eengineer1 Nov 22, 2022
6a9d1f5
Restored ante & post, genesis validation improvements
Eengineer1 Nov 22, 2022
d13a96b
Cleanup
Eengineer1 Nov 22, 2022
07039b5
Fix build
askolesov Nov 23, 2022
b551b16
Debugging
askolesov Nov 23, 2022
251043d
Add JUnit report for Upgrade step
ankurdotb Nov 23, 2022
67b88b2
Make protobuf and checksum tests work
Nov 23, 2022
904d77f
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Nov 23, 2022
fd34178
Separate unit and integration upgrade test
askolesov Nov 23, 2022
92a4d2e
Split fixed fee & simulation gas
Eengineer1 Nov 23, 2022
4ee0ee3
Upgrade test suits
askolesov Nov 23, 2022
b7cd23e
Fix namespaces
askolesov Nov 23, 2022
29eb07b
Debugging
Eengineer1 Nov 23, 2022
44a78b7
Switched to broadcast block
Eengineer1 Nov 23, 2022
31ed074
Switched to lite calc
Eengineer1 Nov 23, 2022
1564f4e
Debugging with default feedecorator
Eengineer1 Nov 23, 2022
8601af8
Added fee payer flag
Eengineer1 Nov 23, 2022
b940811
Debugging
Eengineer1 Nov 23, 2022
e9076cf
Debugging v2
Eengineer1 Nov 23, 2022
3fe752d
Removed simulation checks
Eengineer1 Nov 23, 2022
233a541
Debugging
Eengineer1 Nov 23, 2022
cd0d6ba
Added basic frame & improvements on unit tx lifecycle
Eengineer1 Nov 23, 2022
e16e3ed
Fixed return type
Eengineer1 Nov 23, 2022
79d6739
Minor fixes
askolesov Nov 24, 2022
bc2a432
Extract proto related migrations into it's own files
askolesov Nov 24, 2022
7a09f5b
Commit for sync
Nov 24, 2022
90b5b7c
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Nov 24, 2022
11f0ef4
Fix merge issues
askolesov Nov 24, 2022
2ac37a2
Fixes
askolesov Nov 24, 2022
e8e39c0
Fixed flag
Eengineer1 Nov 24, 2022
8339ee6
Fixed response types
Eengineer1 Nov 24, 2022
80a7e0a
Slight fixes
Eengineer1 Nov 24, 2022
e7c6ac8
Switched base accounts
Eengineer1 Nov 24, 2022
f9f082a
Debugging
Eengineer1 Nov 24, 2022
7add882
Merge remote-tracking branch 'origin/develop' into migration-tests
askolesov Nov 24, 2022
dbaeb2b
Commit for sync
Nov 24, 2022
98ac670
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Nov 24, 2022
ab11e79
Sync
askolesov Nov 24, 2022
33cb450
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
askolesov Nov 24, 2022
d11eba8
Debugging
Eengineer1 Nov 24, 2022
52f9559
Debugging v2
Eengineer1 Nov 24, 2022
33dec78
Debugging v3
Eengineer1 Nov 24, 2022
68bbcc7
Switched to short quantities
Eengineer1 Nov 24, 2022
34de597
Added logs step
Eengineer1 Nov 24, 2022
0b75833
Added overhead
Eengineer1 Nov 24, 2022
c5d496e
Cleanup
Eengineer1 Nov 24, 2022
833da67
Fixed to deterministic order of InitGenesis
Eengineer1 Nov 24, 2022
d82bece
Switched to preceding lite validation
Eengineer1 Nov 24, 2022
c8b847e
Bump from retracted
Eengineer1 Nov 24, 2022
6aa8148
Debugging
Eengineer1 Nov 24, 2022
320fc17
Debugging v2
Eengineer1 Nov 24, 2022
57f3958
Misc
askolesov Nov 25, 2022
20a511d
Make IndyStyle migration works
Nov 25, 2022
243c8e2
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Nov 25, 2022
4d18022
Merge with latest changes
Nov 25, 2022
df08905
Makes linter happy
Nov 25, 2022
d795b13
Reviewing migrations
askolesov Nov 25, 2022
5227b5e
Fix bug
askolesov Nov 25, 2022
c25db46
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
askolesov Nov 25, 2022
d6acc72
Fix merge conflicts
askolesov Nov 25, 2022
de68478
Clean state sync (go.mod & generated protobuf types)
Eengineer1 Nov 25, 2022
18f1b72
Cherry picked
Eengineer1 Nov 25, 2022
8b7d4c9
`gofumpt -ed`
Eengineer1 Nov 25, 2022
b7aabf6
Fixed non-deterministic behavior of InitGenesis
Eengineer1 Nov 25, 2022
0f0275f
Switched to hard typed fee params proto definitions
Eengineer1 Nov 25, 2022
575eb0e
Switched order of querying supply
Eengineer1 Nov 25, 2022
1ac6fcc
Bump Ginkgo & gas adjustment
Eengineer1 Nov 25, 2022
3213ec6
Tidied
Eengineer1 Nov 25, 2022
c1533f3
Bump adjustment
Eengineer1 Nov 25, 2022
7343839
Bumped adjustment
Eengineer1 Nov 25, 2022
aa680c5
Fix iterator issue
askolesov Nov 25, 2022
7521179
Run test pipelines
Nov 28, 2022
b9ac630
Clean up
askolesov Nov 28, 2022
fa2d97f
Review checksumm migration
askolesov Nov 28, 2022
7b5b29e
Restore build tags
askolesov Nov 28, 2022
0d95b36
Extract simple migration helpers
askolesov Nov 28, 2022
19a1df1
Implement version id migration
askolesov Nov 28, 2022
e7c595b
Unstash
Nov 28, 2022
ffa5b0d
Run it on pipelines
Nov 28, 2022
e2f4b69
Fix tests running on pipelines
Nov 28, 2022
6bf2267
Fix cleanup
Nov 28, 2022
1652344
Fix test reporting
askolesov Nov 28, 2022
aef4eda
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
askolesov Nov 28, 2022
cd41843
Remove redundant files
askolesov Nov 28, 2022
884922b
Added integration pricing set
Eengineer1 Nov 28, 2022
949186d
Fixed start time
Eengineer1 Nov 28, 2022
b4d5c7e
Fixed start <> end
Eengineer1 Nov 28, 2022
3f8a5f8
Slight fixes
Eengineer1 Nov 28, 2022
076766d
Added fee grant params generator
Eengineer1 Nov 28, 2022
451d4b9
Added zero checks
Eengineer1 Nov 28, 2022
61289d7
Running whole package
Eengineer1 Nov 28, 2022
fc5ed2e
Added empty base account & improvements
Eengineer1 Nov 28, 2022
c334489
Fixed validation
Eengineer1 Nov 28, 2022
03772c9
Fixed falsy error codes
Eengineer1 Nov 29, 2022
a5d0fce
Restored extras
Eengineer1 Nov 29, 2022
d3e49ea
Fixed race conditions
Eengineer1 Nov 29, 2022
016196a
Add generic dataset implementation
askolesov Nov 29, 2022
0d09f76
Slight fixes
Eengineer1 Nov 29, 2022
71a7b81
Cleanup
askolesov Nov 29, 2022
4456401
Added extra base account
Eengineer1 Nov 29, 2022
5ec5568
Fixed denom
Eengineer1 Nov 29, 2022
9d5e266
Added extra headroom for insufficient funds cases
Eengineer1 Nov 29, 2022
108fd63
Cleanup
askolesov Nov 29, 2022
c740531
Fixed order
Eengineer1 Nov 29, 2022
674fd3b
Switched order for consequent executions and race conditions
Eengineer1 Nov 29, 2022
49266c3
Merge branch 'develop' into ante-impl
Eengineer1 Nov 29, 2022
2aeb9ec
Bypass buf breaking
Eengineer1 Nov 29, 2022
8ff75ea
Add uuid migration
askolesov Nov 29, 2022
10a7df3
Cleanup
Eengineer1 Nov 29, 2022
51b1a0c
Removed debug prints
Eengineer1 Nov 29, 2022
4f42905
`gofumpt -ed`
Eengineer1 Nov 29, 2022
ff3de5b
Add resource version links migration
askolesov Nov 30, 2022
4e7f8a1
Fix build
askolesov Nov 30, 2022
b75eb91
Add unit tests for UUID (#456)
Nov 30, 2022
7154922
Fix version links migration
askolesov Nov 30, 2022
3d4e930
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
askolesov Nov 30, 2022
8a947f6
Restore version links migration
askolesov Nov 30, 2022
35198e2
Cleanup
askolesov Nov 30, 2022
9b44060
Vresion map fix attempt
askolesov Nov 30, 2022
13c7438
Cleanup
askolesov Nov 30, 2022
1bc8de5
Merge branch 'develop' into migration-tests
ankurdotb Nov 30, 2022
c42b8a3
Simplify unit test workflow
ankurdotb Nov 30, 2022
aac9394
Add more migration handlers
askolesov Nov 30, 2022
8531534
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
askolesov Nov 30, 2022
74ed623
Update test.yml
ankurdotb Nov 30, 2022
624443b
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
ankurdotb Nov 30, 2022
cd73c05
Merge branch 'vanilla-upgr-migr-setup' into pricing-clean
Eengineer1 Nov 30, 2022
a2f67e9
Try disabling version map fix
askolesov Dec 1, 2022
2207021
Uncomment integration tests
askolesov Dec 1, 2022
05ae19b
Reorganize file structure
askolesov Dec 1, 2022
102b635
Restore vm fix, fix linter
askolesov Dec 1, 2022
cb6f0da
Add resource links test (#457)
Dec 1, 2022
c44630e
Added upgrade handling for pricing
Eengineer1 Dec 1, 2022
388fa01
Fixed path
Eengineer1 Dec 1, 2022
e5ba96e
Fixed path v2
Eengineer1 Dec 1, 2022
bfc5833
Fixed path v3
Eengineer1 Dec 1, 2022
0317f04
Fixed keys import
Eengineer1 Dec 1, 2022
9a0000d
Added binary replacement step
Eengineer1 Dec 1, 2022
8682c43
Debugging
Eengineer1 Dec 1, 2022
548b8ed
Switched to another base account, race conditions
Eengineer1 Dec 1, 2022
de08fd6
Added co-dependency
Eengineer1 Dec 1, 2022
c980d8c
Switched dep
Eengineer1 Dec 1, 2022
904e6b3
Added extra output trim
Eengineer1 Dec 1, 2022
2d6d49e
Removed dependency
Eengineer1 Dec 1, 2022
7190a35
Fixed allocation
Eengineer1 Dec 1, 2022
53f91ea
Added debug section
Eengineer1 Dec 1, 2022
b65f2f9
Fixed debug statements
Eengineer1 Dec 2, 2022
fcd7c96
Added extra line trim
Eengineer1 Dec 2, 2022
69ed88b
Switched to helper
Eengineer1 Dec 2, 2022
a69649c
Switched to json contents
Eengineer1 Dec 2, 2022
d605361
Restored top level proposal type
Eengineer1 Dec 2, 2022
5751208
Added file passing with permissions
Eengineer1 Dec 2, 2022
685d886
Debugging
Eengineer1 Dec 2, 2022
8bd7da6
Bubble up debug output
Eengineer1 Dec 2, 2022
543337b
Restored post ping
Eengineer1 Dec 2, 2022
caac48f
Switched to unescaped
Eengineer1 Dec 2, 2022
1c69901
Fixed output trim redundant messages
Eengineer1 Dec 2, 2022
00159ce
Removed bloat
Eengineer1 Dec 2, 2022
2cf17a2
Cleanup
Eengineer1 Dec 2, 2022
d39f6cb
Debugging
Eengineer1 Dec 2, 2022
45ede13
Cleanup
Eengineer1 Dec 2, 2022
8b7d1c2
Debugging
Eengineer1 Dec 2, 2022
e0f2923
Fixed order
Eengineer1 Dec 2, 2022
833debd
Skip directly to version
Eengineer1 Dec 2, 2022
342b955
Fixed order
Eengineer1 Dec 2, 2022
caeff34
Added v1 query
Eengineer1 Dec 2, 2022
d6c7398
Registered msg impl
Eengineer1 Dec 2, 2022
376ac69
Added content proto def
Eengineer1 Dec 2, 2022
41966db
Added resource param change proposal
Eengineer1 Dec 3, 2022
eda30d6
Cleanup
Eengineer1 Dec 3, 2022
22078a2
test(migration): Gingko tests for identity pricing migrations [DEV-17…
DaevMithran Dec 3, 2022
5f54f66
Add uuid migration for resource id
askolesov Dec 3, 2022
eced51c
Restored module version map tests
Eengineer1 Dec 3, 2022
21e1a53
Fixed key ref
Eengineer1 Dec 3, 2022
2b8eeff
Merge remote-tracking branch 'origin/develop' into migration-tests
askolesov Dec 3, 2022
bd235de
Commit for sync
Dec 3, 2022
f4fe506
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Dec 3, 2022
f1ffed5
add checksum to datasets
Dec 3, 2022
9fbd777
Add diddoc pre update
askolesov Dec 3, 2022
8610c20
Switched to previous state, non-altering results anyway
Eengineer1 Dec 3, 2022
895e270
Skip InitGenesis of did module
Eengineer1 Dec 3, 2022
a8c229c
Removed migrators as init migrations will be part of the upgrade handler
Eengineer1 Dec 3, 2022
df3cf33
Fix migration unit tests
askolesov Dec 3, 2022
0af4118
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Dec 3, 2022
9e6d7a5
Merge with latest version
Dec 3, 2022
dea1698
Added explicit version set on resource module
Eengineer1 Dec 3, 2022
185a1ea
Fix tests for post checks
Dec 4, 2022
1175434
Makes linter happy
Dec 4, 2022
92a6b1c
Fix pipelines
Dec 5, 2022
6c49264
Fix resource unit tests
Dec 5, 2022
3065abc
Better test structure
askolesov Dec 5, 2022
5084491
Fix loader
askolesov Dec 5, 2022
c71d2ba
Debugging post did update
askolesov Dec 5, 2022
1c67be4
For the previous commit
askolesov Dec 5, 2022
9d73ef9
Fix signature verification bug
askolesov Dec 5, 2022
070b3ea
Added final default params
Eengineer1 Dec 5, 2022
e2cf13e
Added module version map generic fix
Eengineer1 Dec 5, 2022
9eda5a9
Fixed prop expected values
Eengineer1 Dec 5, 2022
66415c9
Add did deactionvation
askolesov Dec 5, 2022
8193409
Fix update and deactivate cases
askolesov Dec 5, 2022
9f7ebc8
Merge branch 'develop' into migration-tests
ankurdotb Dec 5, 2022
9b92ebc
Merge branch 'develop' into ante-impl
ankurdotb Dec 5, 2022
c90e6f7
DIDDoc queries update
ankurdotb Dec 6, 2022
076f08e
Update tx_create_diddoc.go
ankurdotb Dec 6, 2022
a980b12
Update tx_deactivate_diddoc.go
ankurdotb Dec 6, 2022
820caf4
Update tx_update_diddoc.go
ankurdotb Dec 6, 2022
9b14221
Update query_diddoc.go
ankurdotb Dec 6, 2022
1711bbb
Rename create-resource
ankurdotb Dec 6, 2022
4e48dfd
Update go.mod
ankurdotb Dec 6, 2022
33e3b19
Update migration_did_protobuf.go
ankurdotb Dec 6, 2022
2ce9bc0
Add resource default alternative url migration
askolesov Dec 6, 2022
a27f7b8
Merge branch 'migration-tests' of https://github.com/cheqd/cheqd-node…
askolesov Dec 6, 2022
8ebe8bb
Enable default alternative url migration + add test for it, fix build
askolesov Dec 6, 2022
8eb2ef8
Added resource creation after upgrade
Dec 6, 2022
1f2bee7
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Dec 6, 2022
7adf74f
Fix tests
askolesov Dec 6, 2022
c067718
Merge branch 'migration-tests' of github.com:cheqd/cheqd-node into mi…
Dec 6, 2022
8d594ce
Rename create-resource to create for tests
Dec 6, 2022
71789ed
Move resource creation before queries
askolesov Dec 6, 2022
010d63e
Fix resource tests
Dec 6, 2022
718166e
Move directory structure
ankurdotb Dec 6, 2022
54a3769
Checkpoint of notes
Eengineer1 Dec 6, 2022
d097453
Merge remote-tracking branch 'origin/migration-tests' into ante-impl
Eengineer1 Dec 6, 2022
54e7829
Resolving merge with migration tests
Eengineer1 Dec 6, 2022
20593c3
Disabled temporarily breaking action
Eengineer1 Dec 6, 2022
3b71557
Fixed build tags
Eengineer1 Dec 6, 2022
8a2d499
Fixed paths & removed redundant defs
Eengineer1 Dec 6, 2022
b1fd092
Fixed conditional explicit set on version map
Eengineer1 Dec 6, 2022
b7625f6
Restored pre tests
Eengineer1 Dec 6, 2022
09a3730
Added import step
Eengineer1 Dec 6, 2022
fbd3c83
Fixed codec entries
Eengineer1 Dec 7, 2022
4fa0a96
Added separation of decoding stages
Eengineer1 Dec 7, 2022
2378fd3
Bypassing dead link temporarily
Eengineer1 Dec 7, 2022
c3bf149
Fixed order
Eengineer1 Dec 7, 2022
cfc7d11
Added latest defaults
Eengineer1 Dec 7, 2022
e98070d
Added prop expected values
Eengineer1 Dec 7, 2022
3b3c395
Fixed readme dead link
Eengineer1 Dec 7, 2022
d55923c
Minor nits
Eengineer1 Dec 7, 2022
2ca4871
Merge remote-tracking branch 'origin/develop' into ante-impl
Eengineer1 Dec 7, 2022
baf43f6
Remove redundant remarks & fixed typos
Eengineer1 Dec 7, 2022
829f8cf
Temp disabled buf breaking
Eengineer1 Dec 7, 2022
63df1f1
chore: Remove moved dir
Eengineer1 Dec 7, 2022
0c56962
Bump gas adjustment
Eengineer1 Dec 7, 2022
abb0829
Added explicit `gasLimit` cap on fixed fee decl
Eengineer1 Dec 7, 2022
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 .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ jobs:
- uses: bufbuild/buf-lint-action@v1

# Breaking change detection
- uses: bufbuild/buf-breaking-action@v1
with:
input: 'proto'
against: 'https://github.com/cheqd/cheqd-node.git#branch=develop,ref=HEAD~1,subdir=proto'
# - uses: bufbuild/buf-breaking-action@v1
# with:
# input: 'proto'
# against: 'https://github.com/cheqd/cheqd-node.git#branch=develop,ref=HEAD~1,subdir=proto'

super-lint:
name: "Super Linter"
Expand Down
48 changes: 37 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
go install github.com/onsi/ginkgo/v2/ginkgo@latest

- name: Run Ginkgo unit tests
run: ginkgo -r --race --randomize-all --randomize-suites --keep-going --trace --tags upgrade_unit --junit-report report-unit.xml
run: ginkgo -r --tags upgrade_unit --race --randomize-all --randomize-suites --keep-going --trace --junit-report report-unit.xml

- name: Upload unit tests result
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -91,8 +91,14 @@ jobs:

- name: Run Gingko integration tests
working-directory: ./tests/integration
run: ginkgo -r --race --randomize-suites --tags integration --keep-going --trace --junit-report ../../report-integration.xml

run: |
ginkgo -r --tags integration --race --randomize-suites --keep-going --trace --junit-report ../../report-integration.xml

- name: Show logs
if: failure()
working-directory: ./docker/localnet
run: docker compose --env-file build-latest.env logs --tail --follow

- name: Upload integration tests result
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -144,22 +150,42 @@ jobs:
working-directory: ./tests/upgrade/integration
run: |
bash scripts/setup.sh

- name: Run pre-upgrade tests
working-directory: ./tests/upgrade
working-directory: ./tests/upgrade/integration
run: |
ginkgo -r --tags upgrade --race --tags upgrade_integration --focus-file pre_test.go

ginkgo -r --race --tags upgrade_integration --focus-file pre_test.go
- name: Restart network using new node version (build-latest)
working-directory: ./tests/upgrade/integration
run: |
bash scripts/upgrade.sh

- name: Run post-upgrade tests
working-directory: ./tests/upgrade
working-directory: ./tests/upgrade/integration
run: |
ginkgo -r --tags upgrade --race --tags upgrade_integration --focus-file post_test.go

ginkgo -r --race --tags upgrade_integration --focus-file post_test.go
- name: Download binary artifact (build-latest)
uses: actions/download-artifact@v3
id: download
with:
name: cheqd-noded
path: ${{ env.RUNNER_BIN_DIR }}
- name: Restore binary permissions
run: sudo chmod +x ${{ env.RUNNER_BIN_DIR }}/cheqd-noded
- name: Run integration tests on upgraded network
working-directory: ./tests/integration
run: |
ginkgo -r --tags integration --race --randomize-suites --keep-going --trace
- name: Show logs on failure
if: failure()
working-directory: ./docker/localnet
run: docker compose --env-file build-latest.env logs --tail --follow
- name: Submit governance fee parameter change proposals
working-directory: ./tests/upgrade/integration
run: |
ginkgo -r --race --tags upgrade_integration --focus-file param_change_proposal_test.go
- name: Run pricing integration tests after successful param change proposal
working-directory: ./tests/integration
run: |
ginkgo -r --tags integration --race --randomize-suites --keep-going --trace --skip-file cli_diddoc_test.go --skip-file cli_diddoc_negative_test.go --skip-file cli_resource_test.go --skip-file cli_resource_negative_test.go
- name: Cleanup after tests
working-directory: ./tests/upgrade/integration
run: |
Expand Down
13 changes: 13 additions & 0 deletions ante/ante_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ante_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestAnte(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Ante Suite")
}
22 changes: 22 additions & 0 deletions ante/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ante

import (
didtypes "github.com/cheqd/cheqd-node/x/did/types"
resourcetypes "github.com/cheqd/cheqd-node/x/resource/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type BankKeeper interface {
SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
}

type DidKeeper interface {
GetParams(ctx sdk.Context) (params didtypes.FeeParams)
}

type ResourceKeeper interface {
GetParams(ctx sdk.Context) (params resourcetypes.FeeParams)
}
180 changes: 180 additions & 0 deletions ante/fee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package ante

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)

type TxFeeChecker func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error)

// DeductFeeDecorator deducts fees from the first signer of the tx
// If the first signer does not have the funds to pay for the fees, return with InsufficientFunds error
// Call next AnteHandler if fees successfully deducted
// CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator
type DeductFeeDecorator struct {
accountKeeper ante.AccountKeeper
bankKeeper BankKeeper
feegrantKeeper ante.FeegrantKeeper
txFeeChecker TxFeeChecker
}

func NewDeductFeeDecorator(ak ante.AccountKeeper, bk BankKeeper, fk ante.FeegrantKeeper, tfc TxFeeChecker) DeductFeeDecorator {
if tfc == nil {
tfc = checkTxFeeWithValidatorMinGasPrices
}

return DeductFeeDecorator{
accountKeeper: ak,
bankKeeper: bk,
feegrantKeeper: fk,
txFeeChecker: tfc,
}
}

func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

if !simulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas")
}

var (
priority int64
err error
)

fee := feeTx.GetFee()

// check if the tx is a taxable tx
// CONTRACT: Taxable tx is a tx that has at least 1 taxable related Msg.
taxable := IsTaxableTxLite(tx)
// if taxable, include in the mempool
if taxable {
// default priority of tx
newCtx := ctx.WithPriority(priority)
// posthandler will deduct the fee from the fee payer
return next(newCtx, tx, simulate)
}

// if not taxable, follow default
if !simulate {
fee, priority, err = dfd.txFeeChecker(ctx, tx)
if err != nil {
return ctx, err
}
}
if err := dfd.checkDeductFee(ctx, tx, fee); err != nil {
return ctx, err
}

newCtx := ctx.WithPriority(priority)

return next(newCtx, tx, simulate)
}

func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee sdk.Coins) error {
feeTx, ok := sdkTx.(sdk.FeeTx)
if !ok {
return sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

if addr := dfd.accountKeeper.GetModuleAddress(types.FeeCollectorName); addr == nil {
return fmt.Errorf("fee collector module account (%s) has not been set", types.FeeCollectorName)
}

feePayer := feeTx.FeePayer()
feeGranter := feeTx.FeeGranter()
deductFeesFrom := feePayer

// if feegranter set deduct fee from feegranter account.
// this works with only when feegrant enabled.
if feeGranter != nil {
if dfd.feegrantKeeper == nil {
return sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled")
} else if !feeGranter.Equals(feePayer) {
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, sdkTx.GetMsgs())
if err != nil {
return sdkerrors.Wrapf(err, "%s does not not allow to pay fees for %s", feeGranter, feePayer)
}
}

deductFeesFrom = feeGranter
}

deductFeesFromAcc := dfd.accountKeeper.GetAccount(ctx, deductFeesFrom)
if deductFeesFromAcc == nil {
return sdkerrors.ErrUnknownAddress.Wrapf("fee payer address: %s does not exist", deductFeesFrom)
}

// deduct the fees
if !fee.IsZero() {
err := DeductFees(dfd.bankKeeper, ctx, deductFeesFromAcc, fee)
if err != nil {
return err
}
}

events := sdk.Events{
sdk.NewEvent(
sdk.EventTypeTx,
sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()),
sdk.NewAttribute(sdk.AttributeKeyFeePayer, deductFeesFrom.String()),
),
}
ctx.EventManager().EmitEvents(events)

return nil
}

// DeductFees deducts fees from the given account.
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins) error {
if !fees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
}

err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}

return nil
}

func IsSufficientFee(ctx sdk.Context, tax, reward, burn, feeProvided sdk.Coins, gasRequested int64) (bool, int64, error) {
// check if the provided fee is enough for `did`, `resource` module specific Msg
if !feeProvided.IsAnyGTE(tax) {
return false, 0, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeProvided, tax)
}

// check with the default validator min gas prices based on rewards distribution
if ctx.IsCheckTx() {
minGasPrices := ctx.MinGasPrices()
if !minGasPrices.IsZero() {
requiredFees := make(sdk.Coins, len(minGasPrices))

// Determine the required fees by multiplying each required minimum gas
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
glDec := sdk.NewDec(int64(gasRequested))
for i, gp := range minGasPrices {
fee := gp.Amount.Mul(glDec)
requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
}

// check if the fee is sufficient
if !reward.IsAnyGTE(requiredFees) {
return false, 0, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", reward, requiredFees)
}
}
}

priority := getTxPriority(tax, gasRequested)

return true, priority, nil
}
Loading