-
Notifications
You must be signed in to change notification settings - Fork 848
sae: Implement Tx.TransferNonAVAX
#5329
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
Changes from all commits
eb8c0a0
e248997
253c255
3cca8aa
6346d2e
ab83fe6
8f3f888
83cc38b
d606762
0a82734
5b86b6b
3d92bd5
893e17e
83b0ec0
c46bcc2
e92638f
f2faffb
7447b08
8c3b6f0
0369966
85ae854
88a234a
4e261c6
7073c57
d63857d
06d2a41
c28b2d2
aba7590
ca2a5ea
4be05cf
e721e6c
9b4c83f
5d9dd0d
2929163
af11c7e
57b2f73
c583599
2ffbf74
093fbdc
7e58c8e
ae780ec
d657fa3
8573565
2d50a62
5bb64d8
6741731
e70eabb
e74bda2
5a741ec
7709421
2f01ee8
b28d132
f12a1b4
258df6f
8cefe95
fa25c9a
95e7256
5d2ef23
46814f4
58306f5
88c09d1
271658d
9da6af8
7bcb962
34b1457
692f899
eedd62e
e1ece39
9e3bb98
1220398
a4bad9b
56850ce
a41e9a6
22ebf97
c74091e
cefd09f
2ed8fcb
bd9366e
f662e76
163274f
05ddba9
192a266
3fd9a97
1ecbbbe
9b0449c
7e35e32
fca7808
f47cf40
5bdb2df
68a4263
1ede276
01cc4cf
bc6aed5
666066d
affa630
0de4a41
87d29d2
8535be8
61c3b90
6e9545c
47fe30d
adeaa57
6350008
05bb2f4
ba1afe1
166a9c2
e9487dc
51fa5f8
3e3e6aa
9ffcd6c
980daa5
2523cbe
963c295
937c6f8
8ae1a82
3d11e3b
d39ed4d
18c3c2b
ce459c0
05930e4
9e0ffe5
7f3d20d
f40a866
3937331
a6aca7c
99f52e1
18a656e
63fb810
13afb7e
8bb04f6
e6a1d35
28419a7
d75cd34
149b1cb
a781d21
23b9916
c1b9fa8
b4d98b5
81c3c02
9e36643
61dcfbd
ca7c26b
268f6ed
5334079
9b3d867
40c3ba6
3ed6547
f0515ec
6dbe653
9ae76cc
6838983
4e67fcf
97b4ba8
d44b9e6
c5df5ae
f84b71e
900d328
bcc4037
5370371
7eb1978
b9c18ef
21cdd76
cfd18da
b555a85
a5c21d1
eb701ee
1ad0654
1f860c9
921d35d
e340ee9
38c857d
26a19a4
0277d22
342b458
f37215f
f456eac
ac82445
cab3300
8fe92a5
3f7b7c6
efca198
51a986d
86b2b6e
f6faf2d
904a654
a24de25
61a40ce
c4b9ef4
7240e8e
ba626f8
66ed39e
03f7e3e
fcc28ad
458729d
0845724
19b2c1a
6feb25b
7ec149a
517e895
03c4e8f
da34043
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,14 @@ package tx | |
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "math/big" | ||
|
|
||
| "github.com/ava-labs/libevm/common" | ||
|
|
||
| // Imported for [atomic.UnsignedExportTx.Burned] comment resolution. | ||
| _ "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/atomic" | ||
|
|
||
| "github.com/ava-labs/avalanchego/graft/coreth/core/extstate" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we weren't import graft?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of the transition logic, we need to share the libevm registrations during the SAE migration. We can either:
I felt like (1) was less work and wouldn't require moving anything non-SAE related into the SAE codebase (since I presume there is some sprawl in these areas that will be removed once we are in an SAE only world). But you're right that we should be extremely conservative with any dependencies on coreth. I think it should only be for the libevm registrations.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a slippery slope and I don't like importing graft -- I feel like we could get lazy with this. Can we have an SAE package that will be explicitly deprecated and must be removed for things to be 'good', in a similar way we did the RPC stubs and temporary package.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The options here are either to just start working on the migration of those packages or just to decouple with port interfaces. We will inevitably hit these issues so we just need to decide if we will lean on dependency inversion (at least temporary) or just accept importing from graft.
This way my only dependency is the interface while the implementation sits in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it would make sense to try to add some interface indirection. That really only works if you want to own the top and bottom of the stack, but not the middle... For SAE, we want to own the top (but not the bottom) of the stack... So we would need to import graft anyways in that world. I agree that importing graft is something we need to do very sparingly, but I don't think adding a file with a bunch of aliases really helps us that much... It'll be very easy to see where graft is used (by just searching for the imports) and we will need to inspect the usage as we go around whether or not it makes sense to actually depend on that component within graft. |
||
| "github.com/ava-labs/avalanchego/ids" | ||
| "github.com/ava-labs/avalanchego/utils/math" | ||
| "github.com/ava-labs/avalanchego/vms/components/avax" | ||
|
|
@@ -136,3 +138,22 @@ func (e *Export) atomicRequests(txID ids.ID) (ids.ID, *chainsatomic.Requests, er | |
| } | ||
| return e.DestinationChain, &chainsatomic.Requests{PutRequests: elems}, nil | ||
| } | ||
|
|
||
| var errInsufficientFunds = errors.New("insufficient funds") | ||
|
|
||
| // TransferNonAVAX subtracts the non-AVAX balances from the statedb. | ||
| func (e *Export) TransferNonAVAX(avaxAssetID ids.ID, statedb *extstate.StateDB) error { | ||
|
StephenButtolph marked this conversation as resolved.
|
||
| for _, in := range e.Ins { | ||
| if in.AssetID == avaxAssetID { | ||
| continue | ||
| } | ||
|
|
||
| coinID := common.Hash(in.AssetID) | ||
| amount := new(big.Int).SetUint64(in.Amount) | ||
| if balance := statedb.GetBalanceMultiCoin(in.Address, coinID); balance.Cmp(amount) < 0 { | ||
| return fmt.Errorf("%w: address %s asset %s has %d want %d", errInsufficientFunds, in.Address, coinID, balance, amount) | ||
| } | ||
| statedb.SubBalanceMultiCoin(in.Address, coinID, amount) | ||
| } | ||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.