kaspanet / kaspad

Kaspad was the reference full node Kaspa implementation written in Go (golang), now rewritten in Rust: https://github.com/kaspanet/rusty-kaspa
ISC License
457 stars 231 forks source link

UTXO Aggregation and Tracking (Wallet) #1192

Closed aspect closed 3 years ago

aspect commented 3 years ago

This issue tracks wallet subsystem feature integration

We need to bring online and test UTXO tracking APIs currently available in rebase-3 branch - https://github.com/kaspanet/kaspad/tree/feature/karpov-wallet-api-rebased-3

These APIs currently consist of the following two functions:

getUTXOsByAddress(addresses:string[])

This function enumerates available UTXOs for a given set of addresses. This function allows a wallet to establish its UTXO context: the last HD address used and the wallet balance.

This API call currently does not function correctly. As per my understanding, the UTXOs resulting from the call may become unavailable at a later time due to consensus-related data structure mutations.

This is currently the main showstopper as UTXO sets produced by this call can not be reliably used in subsequent transaction issuance. SubmitTransaction() calls produce an error depicted here: https://github.com/kaspanet/kaspad/issues/1158

NotifyUTXOOfAddressChanged()

This subscription method should result in subsequent notifications when changes to an address occur - a UTXO related to an address is added or removed.

Notification functions have not been tested in the external wallet module pending the resolution of https://github.com/kaspanet/kaspad/issues/1158

UTXO/Transaction confirmations

This feature has not yet been implemented. I will be filing this in a separate issue.

@stasatdaglabs this is pending merge in https://github.com/kaspanet/kaspad/pull/1166

stasatdaglabs commented 3 years ago

@aspect acknowledged. Starting to work on this tomorrow

stasatdaglabs commented 3 years ago

Unfortunately this feature had to be rewritten essentially from zero. The following is the new PR: https://github.com/kaspanet/kaspad/pull/1221

Its relative specification: https://github.com/kaspanet/docs/blob/main/Reference/API/wallet.md

Note that the above specification went through a small revision that should make clients' lives a little easier: https://github.com/kaspanet/docs/pull/2

@aspect feel free to try it out, but note that:

aspect commented 3 years ago

@stasatdaglabs can you guys please test-run kaspad with --utxoindex against the kaspaminer. We are building against origin/nod-1597-utxo-index and it appears the miner fails (usually within few seconds) with:

Error submitting block 56d89f93857ccd54bab39e1a5337d9588842989e5f935c80d272152daa130671 to localhost:16210: Block rejected. Reason: cannot add outpoint (802adc6215fccf35e7d1cfc982afa97fb30e02300048b26256eb1db1918832a6: 0) because it's being added already: rpc error

Following are the logs:

kaspad

./kaspad --configfile=/home/aspect/releases/kaspa/kaspad-kd0/kaspad.conf --utxoindex
...
2020-12-17 07:17:10.190 [INF] RPCS: Accepted block 7f7905ef3f528605c844910f155be6c16d1212847935e43d003773583757daf9 via submitBlock
2020-12-17 07:17:10.877 [ERR] TXMP: error from connectionLoops for 127.0.0.1:48336: rpc error: code = Canceled desc = context canceled

kaspaminer

./kaspaminer --miningaddr=kaspatest:qq0nvlmn07f6edcdfynt4nu4l4r58rkquuvgt635ac --rpcserver=localhost:16210 --mine-when-not-synced --testnet
...
2020-12-17 07:17:10.840 [INF] KSMN: Found block 56d89f93857ccd54bab39e1a5337d9588842989e5f935c80d272152daa130671 with parents [9821ccd7c1df61b3b0fbd2023d1f004a1f988df34b4a1071a512bba4fe39e7db 7f7905ef3f528605c844910f155be6c16d1212847935e43d003773583757daf9]. Submitting to localhost:16210
2020-12-17 07:17:10.874 [CRT] KSMN: Exiting: Fatal error in goroutine `mineLoop 3`: Error submitting block 56d89f93857ccd54bab39e1a5337d9588842989e5f935c80d272152daa130671 to localhost:16210: Block rejected. Reason: cannot add outpoint (802adc6215fccf35e7d1cfc982afa97fb30e02300048b26256eb1db1918832a6: 0) because it's being added already: rpc error
main.handleFoundBlock
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/cmd/kaspaminer/mineloop.go:102
main.mineLoop.func1.1
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/cmd/kaspaminer/mineloop.go:47
github.com/kaspanet/kaspad/util/panics.handleSpawnedFunction
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:84
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1.1
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:32
runtime.goexit
        /home/aspect/emanator/tools/go1.14.3/src/runtime/asm_amd64.s:1373
error in mine loop
main.main.func1
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/cmd/kaspaminer/main.go:52
github.com/kaspanet/kaspad/util/panics.handleSpawnedFunction
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:84
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1.1
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:32
runtime.goexit
        /home/aspect/emanator/tools/go1.14.3/src/runtime/asm_amd64.s:1373
2020-12-17 07:17:10.874 [CRT] KSMN: Goroutine stack trace: goroutine 1 [running]:
runtime/debug.Stack(0x0, 0xc000575e08, 0x406bbd)
        /home/aspect/emanator/tools/go1.14.3/src/runtime/debug/stack.go:24 +0x9d
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1(0xab63e6, 0x8, 0xc0000fa180)
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:30 +0x2f
main.main()
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/cmd/kaspaminer/main.go:49 +0x3ed

2020-12-17 07:17:10.874 [CRT] KSMN: Stack trace: goroutine 33 [running]:
runtime/debug.Stack(0xac68a1, 0x22, 0xc000060bd8)
        /home/aspect/emanator/tools/go1.14.3/src/runtime/debug/stack.go:24 +0x9d
github.com/kaspanet/kaspad/util/panics.HandlePanic(0xc0000ab9c0, 0xc000034100, 0xa, 0xc0000d7000, 0x199, 0x400)
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:22 +0x103
panic(0xa2ac80, 0xc0008cda80)
        /home/aspect/emanator/tools/go1.14.3/src/runtime/panic.go:969 +0x166
main.main.func1()
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/cmd/kaspaminer/main.go:52 +0x107
github.com/kaspanet/kaspad/util/panics.handleSpawnedFunction(0xc0000ab9c0, 0xc0000d7000, 0x199, 0x400, 0xab63e6, 0x8, 0xc0000fa180)
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:84 +0x2cc
github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1.1(0xc0000ab9c0, 0xc0000d7000, 0x199, 0x400, 0xab63e6, 0x8, 0xc0000fa180)
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:32 +0x67
created by github.com/kaspanet/kaspad/util/panics.GoroutineWrapperFunc.func1
        /mnt/HC_Volume_6064859/releases/kaspa/kaspad/util/panics/panics.go:31 +0x8c
stasatdaglabs commented 3 years ago

@aspect thank you. It was an oversight on our end. I forgot that AcceptanceData may also include information about transactions that were not accepted, and as such did filter them out. It should be fixed now, as of commit https://github.com/kaspanet/kaspad/pull/1221/commits/6dca43dffc37cbae12bc403e4b0b79fc2342b013

stasatdaglabs commented 3 years ago

Implemented in this PR: https://github.com/kaspanet/kaspad/pull/1221/ Closing since it was merged into a release branch.