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

Preprocess _muxed_id fields before unmarshalling from the DB #3722

Merged
merged 11 commits into from
Jun 25, 2021

Conversation

2opremio
Copy link
Contributor

Fixes #3714 . In particular it fixed the problem found at #3716 (comment)

@2opremio
Copy link
Contributor Author

upon checking all the MuxedID fields programmatically I think I have covered all:

sweepey:stellar-go fons$ grep -r MuxedID * | grep json
protocols/horizon/operations/main.go:	SourceAccountMuxedID  uint64    `json:"source_account_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	FunderMuxedID   uint64 `json:"funder_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	FromMuxedID uint64 `json:"from_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	ToMuxedID   uint64 `json:"to_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	TrustorMuxedID uint64 `json:"trustor_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	TrusteeMuxedID                 uint64 `json:"trustee_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	AccountMuxedID uint64 `json:"account_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	IntoMuxedID    uint64 `json:"into_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	ClaimantMuxedID uint64 `json:"claimant_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	BeginSponsorMuxedID uint64 `json:"begin_sponsor_muxed_id,omitempty,string"`
protocols/horizon/operations/main.go:	FromMuxedID uint64 `json:"from_muxed_id,omitempty,string"`
protocols/horizon/effects/main.go:	AccountMuxedID  uint64    `json:"account_muxed_id,omitempty,string"`
protocols/horizon/effects/main.go:	SellerMuxedID     uint64 `json:"seller_muxed_id,omitempty,string"`
protocols/horizon/main.go:	AccountMuxedID     uint64              `json:"account_muxed_id,omitempty,string"`
protocols/horizon/main.go:	FeeAccountMuxedID  uint64              `json:"fee_account_muxed_id,omitempty,string"`
services/horizon/internal/db2/history/main.go:	SellerMuxedID     uint64 `json:"seller_muxed_id,omitempty"`

I think we are fine with SellerMuxedID not having a ,string but I need to double-check

services/horizon/internal/db2/history/operation.go Outdated Show resolved Hide resolved
@@ -24,15 +25,39 @@ func (r *Operation) UnmarshalDetails(dest interface{}) error {
if !r.DetailsString.Valid {
return nil
}

err := json.Unmarshal([]byte(r.DetailsString.String), &dest)
preprocessedDetails, err := preprocessDetails(r.DetailsString.String)
Copy link
Contributor

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.

Copy link
Contributor

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 in PopulateBaseEffect 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* `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.

I think it is populated (see addAccountAndMuxedAccountDetails(sd, buyer, "seller") in tradeDetails()).

The reason I think it works is because we use an intermediate datastructure (history.TradeEffectDetails, which expects an uint64) before copying the fields to the final effects.Trade data structure (which does have the ,string json tag) in when unmarshalling the details from the database in NewEffect().

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) ).

Copy link
Contributor

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.

Comment on lines 63 to 71
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())
Copy link
Contributor

Choose a reason for hiding this comment

The 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 txnbuild patch release. @stellar/horizon-committers

@bartekn bartekn merged commit 739936f into stellar:release-horizon-v2.5.2 Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants