-
Notifications
You must be signed in to change notification settings - Fork 499
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
Preprocess _muxed_id fields before unmarshalling from the DB #3722
Merged
bartekn
merged 11 commits into
stellar:release-horizon-v2.5.2
from
2opremio:3714-encore
Jun 25, 2021
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2223361
Preprocess _muxed_id fields before unmarshalling from the DB
2opremio 2f337fa
Extend test case to make it fail
2opremio 869f90c
Change JSON decoder to use json.Number instead of float64
2opremio 3ee288c
Add missing string tag
2opremio c4c2049
Add simple integration test
bartekn dc997ca
Fix test
bartekn 7b351b4
Add trade case
bartekn 352da56
Fix unused variable
bartekn 699e70b
Fix txnbuild test
bartekn b49970d
CHANGELOG
bartekn c014572
fixes
bartekn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
services/horizon/internal/integration/muxed_operations_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stellar/go/clients/horizonclient" | ||
"github.com/stellar/go/keypair" | ||
"github.com/stellar/go/services/horizon/internal/test/integration" | ||
"github.com/stellar/go/txnbuild" | ||
"github.com/stellar/go/xdr" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMuxedOperations(t *testing.T) { | ||
itest := integration.NewTest(t, integration.Config{ProtocolVersion: 17}) | ||
|
||
sponsored := keypair.MustRandom() | ||
// Is there an easier way? | ||
sponsoredMuxed := xdr.MustMuxedAddress(sponsored.Address()) | ||
sponsoredMuxed.Type = xdr.CryptoKeyTypeKeyTypeMuxedEd25519 | ||
sponsoredMuxed.Med25519 = &xdr.MuxedAccountMed25519{ | ||
Ed25519: *sponsoredMuxed.Ed25519, | ||
Id: 100, | ||
} | ||
|
||
master := itest.Master() | ||
masterMuxed := xdr.MustMuxedAddress(master.Address()) | ||
masterMuxed.Type = xdr.CryptoKeyTypeKeyTypeMuxedEd25519 | ||
masterMuxed.Med25519 = &xdr.MuxedAccountMed25519{ | ||
Ed25519: *masterMuxed.Ed25519, | ||
Id: 200, | ||
} | ||
|
||
ops := []txnbuild.Operation{ | ||
&txnbuild.BeginSponsoringFutureReserves{ | ||
SponsoredID: sponsored.Address(), | ||
}, | ||
&txnbuild.CreateAccount{ | ||
Destination: sponsored.Address(), | ||
Amount: "100", | ||
}, | ||
&txnbuild.ChangeTrust{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Line: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Limit: txnbuild.MaxTrustlineLimit, | ||
}, | ||
&txnbuild.ManageSellOffer{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Selling: txnbuild.NativeAsset{}, | ||
Buying: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Amount: "3", | ||
Price: "1", | ||
}, | ||
// This will generate a trade effect: | ||
&txnbuild.ManageSellOffer{ | ||
SourceAccount: masterMuxed.Address(), | ||
Selling: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Buying: txnbuild.NativeAsset{}, | ||
Amount: "3", | ||
Price: "1", | ||
}, | ||
&txnbuild.ManageData{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Name: "test", | ||
Value: []byte("test"), | ||
}, | ||
&txnbuild.Payment{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Destination: master.Address(), | ||
Amount: "1", | ||
Asset: txnbuild.NativeAsset{}, | ||
}, | ||
&txnbuild.CreateClaimableBalance{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Amount: "2", | ||
Asset: txnbuild.NativeAsset{}, | ||
Destinations: []txnbuild.Claimant{ | ||
txnbuild.NewClaimant(keypair.MustRandom().Address(), nil), | ||
}, | ||
}, | ||
&txnbuild.EndSponsoringFutureReserves{ | ||
SourceAccount: sponsored.Address(), | ||
}, | ||
} | ||
txResp, err := itest.SubmitMultiSigOperations(itest.MasterAccount(), []*keypair.Full{master, sponsored}, ops...) | ||
assert.NoError(t, err) | ||
assert.True(t, txResp.Successful) | ||
|
||
ops = []txnbuild.Operation{ | ||
// Remove subentries to be able to merge account | ||
&txnbuild.Payment{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Destination: master.Address(), | ||
Amount: "3", | ||
Asset: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
}, | ||
&txnbuild.ChangeTrust{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Line: txnbuild.CreditAsset{"ABCD", master.Address()}, | ||
Limit: "0", | ||
}, | ||
&txnbuild.ManageData{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Name: "test", | ||
}, | ||
&txnbuild.AccountMerge{ | ||
SourceAccount: sponsoredMuxed.Address(), | ||
Destination: masterMuxed.Address(), | ||
}, | ||
} | ||
txResp, err = itest.SubmitMultiSigOperations(itest.MasterAccount(), []*keypair.Full{master, sponsored}, ops...) | ||
assert.NoError(t, err) | ||
assert.True(t, txResp.Successful) | ||
|
||
// Check if no 5xx after processing the tx above | ||
// TODO expand it to test actual muxed fields | ||
_, err = itest.Client().Operations(horizonclient.OperationRequest{Limit: 200}) | ||
assert.NoError(t, err, "/operations failed") | ||
|
||
_, err = itest.Client().Payments(horizonclient.OperationRequest{Limit: 200}) | ||
assert.NoError(t, err, "/payments failed") | ||
|
||
_, err = itest.Client().Effects(horizonclient.EffectRequest{Limit: 200}) | ||
assert.NoError(t, err, "/effects failed") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,9 +63,9 @@ func (am *AccountMerge) FromXDR(xdrOp xdr.Operation, withMuxedAccounts bool) err | |
func (am *AccountMerge) Validate(withMuxedAccounts bool) error { | ||
var err error | ||
if withMuxedAccounts { | ||
_, err = xdr.AddressToAccountId(am.Destination) | ||
} else { | ||
_, err = xdr.AddressToMuxedAccount(am.Destination) | ||
} else { | ||
_, err = xdr.AddressToAccountId(am.Destination) | ||
} | ||
if err != nil { | ||
return NewValidationError("Destination", err.Error()) | ||
Comment on lines
63
to
71
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 changed the order here to be able to merge account into muxed destination. This should be probably a part of |
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we do the same thing for effects? I'll update an integration test to generate a trade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it is working because we are lucky:
account_muxed_id
is done inPopulateBaseEffect
so it's not unmarshaling directly to other struct.seller_muxed_id
is never populated during ingestion, even when seller is a muxed account. This is likely ingestion bug or we just can't extract this information during ingestion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is populated (see
addAccountAndMuxedAccountDetails(sd, buyer, "seller")
intradeDetails()
).The reason I think it works is because we use an intermediate datastructure (
history.TradeEffectDetails
, which expects anuint64
) before copying the fields to the finaleffects.Trade
data structure (which does have the,string
json tag) in when unmarshalling the details from the database inNewEffect()
.This BTW confirms that we don't need a
,string
tag in services/horizon/internal/db2/history/main.go (which I wanted to check in #3722 (comment) ).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@2opremio you are correct. I missed it when checking my test results because I forgot there are always two trade effects for each trade.