Skip to content

Commit

Permalink
feat: withdraw_id in event & limit attest requests (#324) (#326)
Browse files Browse the repository at this point in the history
* optimize reporter daemon

* linting

* add external message pool

* increase the time to commit report

* add migration handling

* refaction migrateStore method

* add test

* test: basic_reporting_test.go fix (#306)

* fix basic_reporting_test.go

* linting

* fix tests

* lint

* cleanup

* add query tips getter

* lint

* use Dec instead Int for reward calculation

* switch queryId field to query_data in QueryMeta

* emit withdraw_id in withdraw tokens msg

* limit external attestation requests

* test: rest of unit tests for each module (#323)

* bring changes from main to release (#244)

* progress

* progress

* progress

* adr1009

* add getters to x/reporter

* edit md

* Add test

* chore: Add backport + release + changelog

* fix

* fix

* fix

---------

Co-authored-by: brendaloya <[email protected]>
Co-authored-by: tkernell <[email protected]>
Co-authored-by: akrem <[email protected]>
Co-authored-by: brendaloya <[email protected]>

* fix: release tag in header (#246) (#247)

(cherry picked from commit 1113ec4)

Co-authored-by: Facundo Medica <[email protected]>

* playground tbr minting (#248) (#250)

(cherry picked from commit 8eeed20)

Co-authored-by: tkernell <[email protected]>

* stake update expiration getter (#249) (#251)

(cherry picked from commit 3d8af49)

Co-authored-by: tkernell <[email protected]>

* feat: Any rpc (#254) (#257)

* change to any rpc url

* remove test function

* remove test file

* remove space

* change suggested stake size

(cherry picked from commit 41bbd2c)

Co-authored-by: spuddy <[email protected]>

* fix: marshal empty vote extensions (#256) (#258)

* changed pipe command on start command to produce two output files. One filtered with just the failed tx info and the other one being all the logs

* changed around pipe command to deal with syntax error

* getting it work without outputting logs to terminal

* created a pipe and a bash script combo that reads in lines of the log file as they come in and filters out to write only failed transactions to the second log file

* successfully started a chain locally and captured filtered logs into a second file now going to try and run it on aws

* better extend vote marshalling

* more voteext error handling

---------

Co-authored-by: Cjpotter10 <[email protected]>
(cherry picked from commit ee55336)

Co-authored-by: tkernell <[email protected]>

* chore: add upgrade handler v2 + reenable ante for MsgCreateValidator (#255) (#259)

* chore: add upgrade handler v2 + reenable ante for MsgCreateValidator

* small lint

(cherry picked from commit a24c352)

Co-authored-by: Facundo Medica <[email protected]>

* chore: modify team address during v0.2.0 upgrade (#261) (#262)

(cherry picked from commit bebb87d)

Co-authored-by: Facundo Medica <[email protected]>

* fix: correct preblocker (#264) (#266)

* fix: correct preblocker

* fix: correct preblocker

* fix: correct preblocker

(cherry picked from commit fa43742)

Co-authored-by: Facundo Medica <[email protected]>

* fix: Rollback upgrade to relaunch (#267) (#268)

(cherry picked from commit 7bc0783)

Co-authored-by: Facundo Medica <[email protected]>

* new token bridge contract (#269) (#270)

(cherry picked from commit 547d611)

Co-authored-by: tkernell <[email protected]>

* fix: Reporter daemon dynamic chainid (#272) (#274)

* new token bridge contract

* dynamic reporter daemon chain id

(cherry picked from commit 483d46f)

Co-authored-by: tkernell <[email protected]>

* hardcoded chain id (#275) (#276)

(cherry picked from commit 2da00fa)

Co-authored-by: CJPotter10 <[email protected]>

* feat: re add MsgCreateValidator check in ante (#271) (#277)

(cherry picked from commit 7e8e420)

Co-authored-by: Facundo Medica <[email protected]>

* chore: ADRs and white paper updates (#278) (#279)

* adrs and wp update

* link fix

* added some graphics to adrs

(cherry picked from commit a32d3c8)

Co-authored-by: brendaloya <[email protected]>

* test: ante.go / extend_vote.go / proposal_handler.go tests  (#285) (#286)

* vote ext suite setup

* linting

* suite problems

* linting

* voteext keyring testing

* app test suites

* proposal handler tests

* process proposal rejected

* process proposal accepted test

* tests

* remove printlns

* revert back to main go.mod

(cherry picked from commit b720c7c)

Co-authored-by: Dan F <[email protected]>

* add globalfee (#283) (#287)

(cherry picked from commit 86f4720)

Co-authored-by: akrem <[email protected]>

* chore: add claim deposit tip to ADR 2001- trb bridge structure (#288) (#289)

* add claim deposit tip to ADR 2001- trb bridge structure

* spelling

(cherry picked from commit bc59938)

Co-authored-by: brendaloya <[email protected]>

* Add selector tips query getter (#290) (#291)

(cherry picked from commit c4761cf)

Co-authored-by: akrem <[email protected]>

* update TellorLayer - Tech.pdf (#293) (#294)

(cherry picked from commit b3eba3c)

Co-authored-by: brendaloya <[email protected]>

* Update version and set min fee (#295) (#296)

* Update version and add fee param

* err handle

(cherry picked from commit 43cba70)

Co-authored-by: akrem <[email protected]>

* Add module to upgrade handler (#297) (#298)

* Update version and add fee param

* err handle

* add module to store upgrade struct

* edit tag

(cherry picked from commit a63d0a9)

Co-authored-by: akrem <[email protected]>

* test: extend_vote.go  (#300) (#301)

* ExtendVoteHandler test cases

* linting

* ExtendVoteHandler tests

(cherry picked from commit de41f56)

Co-authored-by: Dan F <[email protected]>

* fix: remove unnecessary SetParams in upgrade handler (#299) (#302)

* Update version and add fee param

* err handle

* add module to store upgrade struct

* edit tag

* remove setparams from upgrage handler

(cherry picked from commit f8640a0)

Co-authored-by: akrem <[email protected]>

* fix!: Upgrade SDK and IAVL (#307) (#308)

* upgrade things

* add upgrade handler

(cherry picked from commit 7dc72cd)

Co-authored-by: Facundo Medica <[email protected]>

* test: rest of extend_vote.go tests (#309)

* ExtendVoteHandler test cases

* linting

* ExtendVoteHandler tests

* linting

* vote ext keyring tests

* GetOperatorAddress cases

* linting

* mocks and patches cleanup

* linting

* linting

* remove printlns, linting, fix TestCheckAndSignValidatorCheckpoint

* test: rest of extend_vote.go tests (#309) (#310)

* ExtendVoteHandler test cases

* linting

* ExtendVoteHandler tests

* linting

* vote ext keyring tests

* GetOperatorAddress cases

* linting

* mocks and patches cleanup

* linting

* linting

* remove printlns, linting, fix TestCheckAndSignValidatorCheckpoint

(cherry picked from commit f4ac133)

Co-authored-by: Dan F <[email protected]>

* chore: Add tips for token bridge deposits (#304)

* use claim deposit power threshold at time of aggregate

* tests

* add tip param to bridge deposit

* add claimDeposit tip

* add tip param to tokenbridge daemon

* tests

* lint

* use blobstream interface for tokenbridge

* zero token bridge withdrawal tip

* withdraw tip

* separate withdraw limit

* use amount for mintToOracle

* add separate withdraw limit and deposit min

* lint

* updated adr2001 pic

* rename limit update interval const

* bridge pause withdraw

* check state on withdraw

* bridge valset staleness check

* test

* cleanup

* test pause withdraw

* test update

* update evm test readme

* update token bridge contract addr

---------

Co-authored-by: brendaloya <[email protected]>

* registry coverage and linting

* Chore: Fix Merge Conflicts from TokenBridge tips PR (#311)

* bring changes from main to release (#244)

* progress

* progress

* progress

* adr1009

* add getters to x/reporter

* edit md

* Add test

* chore: Add backport + release + changelog

* fix

* fix

* fix

---------

Co-authored-by: brendaloya <[email protected]>
Co-authored-by: tkernell <[email protected]>
Co-authored-by: akrem <[email protected]>
Co-authored-by: brendaloya <[email protected]>

* fix: release tag in header (#246) (#247)

(cherry picked from commit 1113ec4)

Co-authored-by: Facundo Medica <[email protected]>

* playground tbr minting (#248) (#250)

(cherry picked from commit 8eeed20)

Co-authored-by: tkernell <[email protected]>

* stake update expiration getter (#249) (#251)

(cherry picked from commit 3d8af49)

Co-authored-by: tkernell <[email protected]>

* feat: Any rpc (#254) (#257)

* change to any rpc url

* remove test function

* remove test file

* remove space

* change suggested stake size

(cherry picked from commit 41bbd2c)

Co-authored-by: spuddy <[email protected]>

* fix: marshal empty vote extensions (#256) (#258)

* changed pipe command on start command to produce two output files. One filtered with just the failed tx info and the other one being all the logs

* changed around pipe command to deal with syntax error

* getting it work without outputting logs to terminal

* created a pipe and a bash script combo that reads in lines of the log file as they come in and filters out to write only failed transactions to the second log file

* successfully started a chain locally and captured filtered logs into a second file now going to try and run it on aws

* better extend vote marshalling

* more voteext error handling

---------

Co-authored-by: Cjpotter10 <[email protected]>
(cherry picked from commit ee55336)

Co-authored-by: tkernell <[email protected]>

* chore: add upgrade handler v2 + reenable ante for MsgCreateValidator (#255) (#259)

* chore: add upgrade handler v2 + reenable ante for MsgCreateValidator

* small lint

(cherry picked from commit a24c352)

Co-authored-by: Facundo Medica <[email protected]>

* chore: modify team address during v0.2.0 upgrade (#261) (#262)

(cherry picked from commit bebb87d)

Co-authored-by: Facundo Medica <[email protected]>

* fix: correct preblocker (#264) (#266)

* fix: correct preblocker

* fix: correct preblocker

* fix: correct preblocker

(cherry picked from commit fa43742)

Co-authored-by: Facundo Medica <[email protected]>

* fix: Rollback upgrade to relaunch (#267) (#268)

(cherry picked from commit 7bc0783)

Co-authored-by: Facundo Medica <[email protected]>

* new token bridge contract (#269) (#270)

(cherry picked from commit 547d611)

Co-authored-by: tkernell <[email protected]>

* fix: Reporter daemon dynamic chainid (#272) (#274)

* new token bridge contract

* dynamic reporter daemon chain id

(cherry picked from commit 483d46f)

Co-authored-by: tkernell <[email protected]>

* hardcoded chain id (#275) (#276)

(cherry picked from commit 2da00fa)

Co-authored-by: CJPotter10 <[email protected]>

* feat: re add MsgCreateValidator check in ante (#271) (#277)

(cherry picked from commit 7e8e420)

Co-authored-by: Facundo Medica <[email protected]>

* chore: ADRs and white paper updates (#278) (#279)

* adrs and wp update

* link fix

* added some graphics to adrs

(cherry picked from commit a32d3c8)

Co-authored-by: brendaloya <[email protected]>

* test: ante.go / extend_vote.go / proposal_handler.go tests  (#285) (#286)

* vote ext suite setup

* linting

* suite problems

* linting

* voteext keyring testing

* app test suites

* proposal handler tests

* process proposal rejected

* process proposal accepted test

* tests

* remove printlns

* revert back to main go.mod

(cherry picked from commit b720c7c)

Co-authored-by: Dan F <[email protected]>

* add globalfee (#283) (#287)

(cherry picked from commit 86f4720)

Co-authored-by: akrem <[email protected]>

* chore: add claim deposit tip to ADR 2001- trb bridge structure (#288) (#289)

* add claim deposit tip to ADR 2001- trb bridge structure

* spelling

(cherry picked from commit bc59938)

Co-authored-by: brendaloya <[email protected]>

* Add selector tips query getter (#290) (#291)

(cherry picked from commit c4761cf)

Co-authored-by: akrem <[email protected]>

* update TellorLayer - Tech.pdf (#293) (#294)

(cherry picked from commit b3eba3c)

Co-authored-by: brendaloya <[email protected]>

* Update version and set min fee (#295) (#296)

* Update version and add fee param

* err handle

(cherry picked from commit 43cba70)

Co-authored-by: akrem <[email protected]>

* Add module to upgrade handler (#297) (#298)

* Update version and add fee param

* err handle

* add module to store upgrade struct

* edit tag

(cherry picked from commit a63d0a9)

Co-authored-by: akrem <[email protected]>

* test: extend_vote.go  (#300) (#301)

* ExtendVoteHandler test cases

* linting

* ExtendVoteHandler tests

(cherry picked from commit de41f56)

Co-authored-by: Dan F <[email protected]>

* use claim deposit power threshold at time of aggregate

* tests

* add tip param to bridge deposit

* add claimDeposit tip

* add tip param to tokenbridge daemon

* fix: remove unnecessary SetParams in upgrade handler (#299) (#302)

* Update version and add fee param

* err handle

* add module to store upgrade struct

* edit tag

* remove setparams from upgrage handler

(cherry picked from commit f8640a0)

Co-authored-by: akrem <[email protected]>

* tests

* lint

* use blobstream interface for tokenbridge

* zero token bridge withdrawal tip

* withdraw tip

* fix!: Upgrade SDK and IAVL (#307) (#308)

* upgrade things

* add upgrade handler

(cherry picked from commit 7dc72cd)

Co-authored-by: Facundo Medica <[email protected]>

* separate withdraw limit

* use amount for mintToOracle

* add separate withdraw limit and deposit min

* lint

* updated adr2001 pic

* rename limit update interval const

* bridge pause withdraw

* check state on withdraw

* bridge valset staleness check

* test

* cleanup

* test pause withdraw

* test update

* update evm test readme

* test: rest of extend_vote.go tests (#309) (#310)

* ExtendVoteHandler test cases

* linting

* ExtendVoteHandler tests

* linting

* vote ext keyring tests

* GetOperatorAddress cases

* linting

* mocks and patches cleanup

* linting

* linting

* remove printlns, linting, fix TestCheckAndSignValidatorCheckpoint

(cherry picked from commit f4ac133)

Co-authored-by: Dan F <[email protected]>

* update token bridge contract addr

---------

Co-authored-by: Facundo Medica <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: akrem <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: spuddy <[email protected]>
Co-authored-by: CJPotter10 <[email protected]>
Co-authored-by: Dan F <[email protected]>
Co-authored-by: akrem <[email protected]>

* Chore: Delete PNG for merge (#313)

* bring changes from main to release (#244)

* progress

* progress

* progress

* adr1009

* add getters to x/reporter

* edit md

* Add test

* chore: Add backport + release + changelog

* fix

* fix

* fix

---------

Co-authored-by: brendaloya <[email protected]>
Co-authored-by: tkernell <[email protected]>
Co-authored-by: akrem <[email protected]>
Co-authored-by: brendaloya <[email protected]>

* fix: release tag in header (#246) (#247)

(cherry picked from commit 1113ec4)

Co-authored-by: Facundo Medica <[email protected]>

* playground tbr minting (#248) (#250)

(cherry picked from commit 8eeed20)

Co-authored-by: tkernell <[email protected]>

* stake update expiration getter (#249) (#251)

(cherry picked from commit 3d8af49)

Co-authored-by: tkernell <[email protected]>

* feat: Any rpc (#254) (#257)

* change to any rpc url

* remove test function

* remove test file

* remove space

* change suggested stake size

(cherry picked from commit 41bbd2c)

Co-authored-by: spuddy <[email protected]>

* fix: marshal empty vote extensions (#256) (#258)

* changed pipe command on start command to produce two output files. One filtered with just the failed tx info and the other one being all the logs

* changed around pipe command to deal with syntax error

* getting it work without outputting logs to terminal

* created a pipe and a bash script combo that reads in lines of the log file as they come in and filters out to write only failed transactions to the second log file

* successfully started a chain locally and captured filtered logs into a second file now going to try and run it on aws

* better extend vote marshalling

* more voteext error handling

---------

Co-authored-by: Cjpotter10 <[email protected]>
(cherry picked from commit ee55336)

Co-authored-by: tkernell <[email protected]>

* chore: add upgrade handler v2 + reenable ante for MsgCreateValidator (#255) (#259)

* chore: add upgrade handler v2 + reenable ante for MsgCreateValidator

* small lint

(cherry picked from commit a24c352)

Co-authored-by: Facundo Medica <[email protected]>

* chore: modify team address during v0.2.0 upgrade (#261) (#262)

(cherry picked from commit bebb87d)

Co-authored-by: Facundo Medica <[email protected]>

* fix: correct preblocker (#264) (#266)

* fix: correct preblocker

* fix: correct preblocker

* fix: correct preblocker

(cherry picked from commit fa43742)

Co-authored-by: Facundo Medica <[email protected]>

* fix: Rollback upgrade to relaunch (#267) (#268)

(cherry picked from commit 7bc0783)

Co-authored-by: Facundo Medica <[email protected]>

* new token bridge contract (#269) (#270)

(cherry picked from commit 547d611)

Co-authored-by: tkernell <[email protected]>

* fix: Reporter daemon dynamic chainid (#272) (#274)

* new token bridge contract

* dynamic reporter daemon chain id

(cherry picked from commit 483d46f)

Co-authored-by: tkernell <[email protected]>

* hardcoded chain id (#275) (#276)

(cherry picked from commit 2da00fa)

Co-authored-by: CJPotter10 <[email protected]>

* feat: re add MsgCreateValidator check in ante (#271) (#277)

(cherry picked from commit 7e8e420)

Co-authored-by: Facundo Medica <[email protected]>

* chore: ADRs and white paper updates (#278) (#279)

* adrs and wp update

* link fix

* added some graphics to adrs

(cherry picked from commit a32d3c8)

Co-authored-by: brendaloya <[email protected]>

* test: ante.go / extend_vote.go / proposal_handler.go tests  (#285) (#286)

* vote ext suite setup

* linting

* suite problems

* linting

* voteext keyring testing

* app test suites

* proposal handler tests

* process proposal rejected

* process proposal accepted test

* tests

* remove printlns

* revert back to main go.mod

(cherry picked from commit b720c7c)

Co-authored-by: Dan F <[email protected]>

* add globalfee (#283) (#287)

(cherry picked from commit 86f4720)

Co-authored-by: akrem <[email protected]>

* chore: add claim deposit tip to ADR 2001- trb bridge structure (#288) (#289)

* add claim deposit tip to ADR 2001- trb bridge structure

* spelling

(cherry picked from commit bc59938)

Co-authored-by: brendaloya <[email protected]>

* Add selector tips query getter (#290) (#291)

(cherry picked from commit c4761cf)

Co-authored-by: akrem <[email protected]>

* update TellorLayer - Tech.pdf (#293) (#294)

(cherry picked from commit b3eba3c)

Co-authored-by: brendaloya <[email protected]>

* Update version and set min fee (#295) (#296)

* Update version and add fee param

* err handle

(cherry picked from commit 43cba70)

Co-authored-by: akrem <[email protected]>

* Add module to upgrade handler (#297) (#298)

* Update version and add fee param

* err handle

* add module to store upgrade struct

* edit tag

(cherry picked from commit a63d0a9)

Co-authored-by: akrem <[email protected]>

* test: extend_vote.go  (#300) (#301)

* ExtendVoteHandler test cases

* linting

* ExtendVoteHandler tests

(cherry picked from commit de41f56)

Co-authored-by: Dan F <[email protected]>

* use claim deposit power threshold at time of aggregate

* tests

* add tip param to bridge deposit

* add claimDeposit tip

* add tip param to tokenbridge daemon

* fix: remove unnecessary SetParams in upgrade handler (#299) (#302)

* Update version and add fee param

* err handle

* add module to store upgrade struct

* edit tag

* remove setparams from upgrage handler

(cherry picked from commit f8640a0)

Co-authored-by: akrem <[email protected]>

* tests

* lint

* use blobstream interface for tokenbridge

* zero token bridge withdrawal tip

* withdraw tip

* fix!: Upgrade SDK and IAVL (#307) (#308)

* upgrade things

* add upgrade handler

(cherry picked from commit 7dc72cd)

Co-authored-by: Facundo Medica <[email protected]>

* separate withdraw limit

* use amount for mintToOracle

* add separate withdraw limit and deposit min

* lint

* updated adr2001 pic

* rename limit update interval const

* bridge pause withdraw

* check state on withdraw

* bridge valset staleness check

* test

* cleanup

* test pause withdraw

* test update

* update evm test readme

* test: rest of extend_vote.go tests (#309) (#310)

* ExtendVoteHandler test cases

* linting

* ExtendVoteHandler tests

* linting

* vote ext keyring tests

* GetOperatorAddress cases

* linting

* mocks and patches cleanup

* linting

* linting

* remove printlns, linting, fix TestCheckAndSignValidatorCheckpoint

(cherry picked from commit f4ac133)

Co-authored-by: Dan F <[email protected]>

* update token bridge contract addr

* tmp delete png

---------

Co-authored-by: Facundo Medica <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: akrem <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: spuddy <[email protected]>
Co-authored-by: CJPotter10 <[email protected]>
Co-authored-by: Dan F <[email protected]>
Co-authored-by: akrem <[email protected]>

* Update client.go (#315)

* added pic for adr2001 (#316)

* Chore: Claim Deposits in Batches (#318)

* add batch claim deposits

* remove old claimdeposit msg

* upgrade name change (#320)

* linting

* .

* fix tests from merge

* oracle/token_bridge_deposit.go tests

* reporter module tests

* bridge module tests

---------

Co-authored-by: Facundo Medica <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: tkernell <[email protected]>
Co-authored-by: akrem <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: spuddy <[email protected]>
Co-authored-by: CJPotter10 <[email protected]>
Co-authored-by: akrem <[email protected]>

* update upgrade name

---------

Co-authored-by: akrem <[email protected]>
Co-authored-by: Dan F <[email protected]>
Co-authored-by: Facundo Medica <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: brendaloya <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: spuddy <[email protected]>
Co-authored-by: CJPotter10 <[email protected]>
Co-authored-by: akrem <[email protected]>
(cherry picked from commit 3b1b11a)

Co-authored-by: tkernell <[email protected]>
  • Loading branch information
github-actions[bot] and tkernell authored Sep 6, 2024
1 parent e11d27c commit 1ba5fb6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
7 changes: 5 additions & 2 deletions x/bridge/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func (k Keeper) CreateNewReportSnapshots(ctx context.Context) error {
if err != nil {
return nil
}
err = k.CreateSnapshot(ctx, queryId, reportTime)
err = k.CreateSnapshot(ctx, queryId, reportTime, false)
if err != nil {
return err
}
Expand All @@ -795,7 +795,7 @@ func (k Keeper) CreateNewReportSnapshots(ctx context.Context) error {
}

// Called with each new agg report and with new request for optimistic attestations
func (k Keeper) CreateSnapshot(ctx context.Context, queryId []byte, timestamp time.Time) error {
func (k Keeper) CreateSnapshot(ctx context.Context, queryId []byte, timestamp time.Time, isExternalRequest bool) error {
aggReport, err := k.oracleKeeper.GetAggregateByTimestamp(ctx, queryId, timestamp)
if err != nil {
k.Logger(ctx).Info("Error getting aggregate report by timestamp", "error", err)
Expand Down Expand Up @@ -915,6 +915,9 @@ func (k Keeper) CreateSnapshot(ctx context.Context, queryId []byte, timestamp ti
k.Logger(ctx).Info("Error getting attestation requests by height", "error", err)
return err
}
if isExternalRequest && len(attestRequests.Requests) > 40 {
return errors.New("too many external requests")
}
request := types.AttestationRequest{
Snapshot: snapshotBytes,
}
Expand Down
2 changes: 1 addition & 1 deletion x/bridge/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ func TestCreateSnapshot(t *testing.T) {
})
require.NoError(t, err)

err = k.CreateSnapshot(ctx, queryId, timestamp)
err = k.CreateSnapshot(ctx, queryId, timestamp, false)
require.NoError(t, err)

// check if snapshot is created
Expand Down
2 changes: 1 addition & 1 deletion x/bridge/keeper/msg_server_request_attestations.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (k msgServer) RequestAttestations(ctx context.Context, msg *types.MsgReques
return nil, status.Error(codes.InvalidArgument, err.Error())
}
timestamp := time.UnixMilli(int64(timestampInt))
err = k.Keeper.CreateSnapshot(sdkCtx, queryId, timestamp)
err = k.Keeper.CreateSnapshot(sdkCtx, queryId, timestamp, true)
if err != nil {
k.Keeper.Logger(sdkCtx).Error("failed to create snapshot", "error", err)
return nil, status.Error(codes.Internal, err.Error())
Expand Down
5 changes: 4 additions & 1 deletion x/bridge/keeper/msg_server_withdraw_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"
"encoding/hex"
"strconv"

layer "github.com/tellor-io/layer/types"
"github.com/tellor-io/layer/x/bridge/types"
Expand All @@ -25,7 +26,8 @@ func (k msgServer) WithdrawTokens(goCtx context.Context, msg *types.MsgWithdrawT
return nil, sdkerrors.ErrInvalidRequest
}

if err := k.Keeper.WithdrawTokens(sdkCtx, msg.Amount, sender, recipient); err != nil {
withdrawalId, err := k.Keeper.WithdrawTokens(sdkCtx, msg.Amount, sender, recipient)
if err != nil {
return nil, err
}
sdk.UnwrapSDKContext(goCtx).EventManager().EmitEvents(sdk.Events{
Expand All @@ -34,6 +36,7 @@ func (k msgServer) WithdrawTokens(goCtx context.Context, msg *types.MsgWithdrawT
sdk.NewAttribute("sender", msg.Creator),
sdk.NewAttribute("recipient_evm_address", msg.Recipient),
sdk.NewAttribute("amount", msg.Amount.String()),
sdk.NewAttribute("withdraw_id", strconv.FormatUint(withdrawalId, 10)),
),
})
return &types.MsgWithdrawTokensResponse{}, nil
Expand Down
16 changes: 10 additions & 6 deletions x/bridge/keeper/withdraw_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k Keeper) WithdrawTokens(ctx context.Context, amount sdk.Coin, sender sdk.AccAddress, recipient []byte) error {
func (k Keeper) WithdrawTokens(ctx context.Context, amount sdk.Coin, sender sdk.AccAddress, recipient []byte) (uint64, error) {
// send coins from the sender to the bridge module
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, sdk.NewCoins(amount)); err != nil {
return err
return 0, err
}
// burn the coins
if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(amount)); err != nil {
return err
return 0, err
}

withdrawalId, err := k.IncrementWithdrawalId(ctx)
if err != nil {
return err
return 0, err
}

aggregate, err := k.CreateWithdrawalAggregate(ctx, amount, sender, recipient, withdrawalId)
if err != nil {
return err
return 0, err
}

return k.oracleKeeper.SetAggregate(ctx, aggregate)
err = k.oracleKeeper.SetAggregate(ctx, aggregate)
if err != nil {
return 0, err
}
return withdrawalId, nil
}

func (k Keeper) IncrementWithdrawalId(goCtx context.Context) (uint64, error) {
Expand Down
3 changes: 2 additions & 1 deletion x/bridge/keeper/withdraw_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func TestWithdrawTokens(t *testing.T) {
bk.On("SendCoinsFromAccountToModule", ctx, creatorAddr, types.ModuleName, sdk.NewCoins(amount)).Return(nil)
bk.On("BurnCoins", ctx, types.ModuleName, sdk.NewCoins(amount)).Return(nil)

err = k.WithdrawTokens(ctx, amount, creatorAddr, []byte(recipientAddr))
withdrawId, err := k.WithdrawTokens(ctx, amount, creatorAddr, []byte(recipientAddr))
require.NoError(t, err)
require.Equal(t, withdrawId, uint64(1))
}

0 comments on commit 1ba5fb6

Please sign in to comment.