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

X-chain - Repack tx builder #2972

Closed
wants to merge 115 commits into from
Closed

X-chain - Repack tx builder #2972

wants to merge 115 commits into from

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Apr 26, 2024

Why this should be merged

Dynamic fees will radically chance the way we build transactions. Fees won't be known ahead of time, but will be iterativelly calculated as inputs and outputs are added to the tx.
On top of this we have at least three ways to build transactions currently:

  • Using wallet's builder
  • With ad-hoc functions in X-chain APIs (deprecated and soon to be removed in favour of wallet)
  • Manually laying out txs in unit tests

This code duplication is a maintenance nightmare as we introduce dynamic fees.
This PR simplify the maintenance burned in two ways:

  • Pulls out of X-chain APIs, txs builders
  • Makes txs builders use wallet builders to create transaction

In a coming PR, unit tests are update to make use of the txs builders instead of manually laying out txs, so to have a unified and maintainable way to build X-chain txs

How this works

  • Pull out of X-chain APIs, txs builders
  • Make txs builders use wallet builders to create transaction
  • Drop most of utxo.Spend methods (since wallet is used instead)

How this was tested

CI

@abi87 abi87 self-assigned this Apr 26, 2024
@@ -60,7 +60,10 @@ type FormattedAssetID struct {
}

// Service defines the base service for the asset vm
type Service struct{ vm *VM }
Copy link
Contributor Author

@abi87 abi87 Apr 26, 2024

Choose a reason for hiding this comment

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

most of the code in this files has been:

  • Moved to txs/builder/builder.go file
  • replaced by wallet machinery

@@ -98,35 +95,6 @@ func (w *WalletService) issue(tx *txs.Tx) (ids.ID, error) {
return txID, nil
}

func (w *WalletService) update(utxos []*avax.UTXO) ([]*avax.UTXO, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to wallet_service_backend.go

@@ -1555,27 +1555,27 @@ func TestServiceGetTxJSON_OperationTxWithPropertyFxMintOpMultiple(t *testing.T)
func newAvaxBaseTxWithOutputs(t *testing.T, genesisBytes []byte, chainID ids.ID, fee uint64, parser txs.Parser) *txs.Tx {
avaxTx := getCreateTxFromGenesisTest(t, genesisBytes, "AVAX")
key := keys[0]
tx := buildBaseTx(avaxTx, chainID, fee, key)
tx := buildTestBaseTx(avaxTx, chainID, fee, key)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these renamings here avoid conflicts with functions defined in tx_builders.go. We will further simplify this test code in next PR, #2736

[][]*secp256k1.PrivateKey, // signers
error,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SpendNFT is the only function I have not dropped, since it's not obvious to me whether is should be moved to the wallet.
Keeping it here for now

// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package avm
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the naming for stuff in this file is a bit confusing and suggests that it might be better for us to put this in its own package. Maybe we can make a new package for this component that we can call avm/wallet so we can just call this wallet.Wallet instead of avm.walletServiceBuilderBackend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd go for the P-chain structure.
In platformvm we used to have a txs/builder package, which now has been renamed to txs/txstest since those builders are only used in tests.
Here I'd keep a txs/builder package as long as these builder are used in the APIs

vms/avm/tx_builders.go Outdated Show resolved Hide resolved
vms/avm/tx_builders.go Outdated Show resolved Hide resolved

var _ txBuilderBackend = (*walletServiceBackend)(nil)

func NewWalletServiceBackend(vm *VM) *walletServiceBackend {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we accept an UTXOReader instead of the concrete *VM type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the vm here is used by wallet service as well. I'd keep vm to centralize access

vms/avm/wallet_service_backend.go Outdated Show resolved Hide resolved
vms/avm/tx_builders.go Outdated Show resolved Hide resolved
vms/avm/wallet_service_backend.go Outdated Show resolved Hide resolved
@abi87 abi87 requested a review from joshua-kim May 9, 2024 14:15
@@ -0,0 +1,30 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the file organization of this folder is very similar to what we do in P-chain.
The difference is that in platformvm we don't have multiple backends (wallet and service backends), so we can fully define the backend in the tx builder package.

@abi87
Copy link
Contributor Author

abi87 commented May 21, 2024

Closing this dow since we reached agreement on not upgrading deprecated X-chain APIs to Dynamic fees.
APIs will stop working when Dynamic fees will be activated
#2736 will upgrade unit tests to use a wallet based builder, in order to simplify maintenance

@abi87 abi87 closed this May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants