stellar / js-stellar-base

The lowest-level stellar helper library. It consists of classes to read, write, hash, and sign Stellar xdr
https://stellar.github.io/js-stellar-base/
Apache License 2.0
106 stars 138 forks source link

Using fee-bump with Soroban transactions requires doubling the inner tx fee #749

Open kalepail opened 3 months ago

kalepail commented 3 months ago

Full context on Discord https://discord.com/channels/897514728459468821/1245935726424752220

Describe the bug When wrapping a Soroban transaction in a fee-bump transaction you're required to match the inner tx base fee which effectively doubles the quote price of the transaction.

Here's an example

AAAABQAAAABQECxBd0OuvEZCPrXlzF2/KQQpwJD0ed7uK4vPZ6A9hwAAAAACfqMUAAAAAgAAAAAIMRarW2LO2GZ6lScinIR0+CECrUHivNP+6BJc3zEL1QE/KnoAHJSYAAAACAAAAAEAAAAAAAAAAAAAAABmWT12AAAAAAAAAAEAAAAAAAAAGAAAAAAAAAABHN579wJ8O5BfFisKZCaMjA1tYZtcPlVuOSMRW7RDd98AAAAGZGVwbG95AAAAAAACAAAADQAAACBLD+IRw8zUkKwAPsZgoLywmgpZUrxYzum6ClDBefH7BgAAAA0AAABBBAcQXRv+f+kRjdyoHQGXAyiJnEJ/kVczkIXrc0/0F2BNs2nygJr6ircqlF/59ONO//07CDEWltBIMubu6jjM2WUAAAAAAAAAAAAAAQAAAAAAAAADAAAABgAAAAEc3nv3Anw7kF8WKwpkJoyMDW1hm1w+VW45IxFbtEN33wAAABQAAAABAAAAB1D3fx7c/cpL0nVTC0jy5V1sNPzDkRG8hmxak/6zhCJdAAAAB+/U5X3hDAM20j42nL3RePNDVgEJbq0pKbOh7KYCQcNHAAAAAgAAAAYAAAABuHqGseBXUIPAHcksO2o+KiFwzTgADVuggBffwvUx1PoAAAANAAAAIEsP4hHDzNSQrAA+xmCgvLCaCllSvFjO6boKUMF58fsGAAAAAQAAAAYAAAABuHqGseBXUIPAHcksO2o+KiFwzTgADVuggBffwvUx1PoAAAAUAAAAAQAuJ9YAAChsAAABkAAAAAABPyoWAAAAAd8xC9UAAABAzDPZILljCYGq6MH7+2s0FLmvNOSy/QPio1/OYQY9mHr5rs1arm6hZbUakjR+6eWmwe7nffa1KuajCOQ70iKgBAAAAAAAAAABZ6A9hwAAAECbu/m+vzVjytsxWzj8YaglgWFEU3x2DqZA68/qQp5Kb/C1Xw4BVeKb8UYBJhsO16+vEWBboExpgYnlkekxSn0K

If I try and use a smaller outer fee when fee-bumping via something like TransactionBuilder.buildFeeBumpTransaction(keypair, (10_000).toString(), transaction, Networks.TESTNET); I get an error Invalid baseFee, it should be at least 20916858 stroops.

We're kinda retrofitting the current fee as a "per operation" construct as Soroban transactions can only have the one operation. I'm unsure if this is a Core, Horizon or JS SDK bug but requiring a doubling of your fee to fee-bump isn't ideal.

What version are you on? v12.0.0

Additional context Tested this by modifying js-stellar-base https://github.com/stellar/js-stellar-base/compare/master...inner-fee-fix By removing the throw and more manually setting the fee I can get a much smaller fee to submit successfully. So in this case I think the JS SDK is trying to be too smart

TransactionBuilder.buildFeeBumpTransaction also 2x the fee (in order to cover both the inner ops and the outer fee-bump "op")

In most cases this is useful and helpful, but in the Soroban instance this really doesn't work. I'm not sure exactly what the answer here is but likely it's creating a smarter error or just removing it altogether and then allowing the TransactionBuilder.buildFeeBumpTransaction fee field to actually set the fee for the whole tx vs per op. Or maybe a new TransactionBuilder altogether that's custom built for handling wrapping Soroban transctions.