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

elementsregtest (liquidregtest) chain with initialfreecoins cause electrs panic #125

Open
philippem opened this issue Oct 28, 2024 · 4 comments

Comments

@philippem
Copy link
Collaborator

While attempting to index an elementsregtest chain that has initialfreecoins=2100000000000000 in its elements.conf and where there are transactions that use free coins, electrs panics.
The stack trace is below.

This scenario can be reproduced using an elements daemon configured using https://elementsproject.org/elements-code-tutorial/overview, or in https://github.com/philippem/elements-docker-compose/tree/add-esplora

INFO hash=76ba9c5ec283434e2590c329e5fd580eb4a0773312f3571df03c181bcd4844e2 height=200 @ 2024-10-28T11:21:33Z (201 left to index)
DEBUG adding transactions from 0 blocks using Bitcoind
DEBUG indexing history from 201 blocks using Bitcoind
DEBUG hash=76ba9c5ec283434e2590c329e5fd580eb4a0773312f3571df03c181bcd4844e2 height=200 @ 2024-10-28T11:21:33Z (201 left to index)
DEBUG last fetch Some(hash=a6f5e196ef71860082a1e15a7abe4361a832612382d3d389b0f46981007e4ba3 height=99 @ 2024-10-28T11:15:43Z)
DEBUG last fetch Some(hash=08a7a34bc4c7fe890b84d887341708c32bdd0e27a5066331708b63da8edb3980 height=199 @ 2024-10-28T11:21:33Z)
thread 'main' panicked at src/new_index/schema.rs:330:76:
called `Result::unwrap()` on an `Err` value: Error(Msg("missing txo [elements]cb4953dfe64aba4687d0de08e5ce17d8f7640deeef63be4ac3bac3afdefdfd78:0"), State { next_error: None, backtrace: InternalBacktrace { backtrace: Some(   0: backtrace::backtrace::libunwind::trace
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.69/src/backtrace/libunwind.rs:93:5
      backtrace::backtrace::trace_unsynchronized
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.69/src/backtrace/mod.rs:66:5
   1: backtrace::backtrace::trace
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.69/src/backtrace/mod.rs:53:14
   2: backtrace::capture::Backtrace::create
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.69/src/capture.rs:176:9
   3: backtrace::capture::Backtrace::new_unresolved
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.69/src/capture.rs:170:9
   4: error_chain::backtrace::imp::InternalBacktrace::new
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/error-chain-0.12.4/src/backtrace.rs:56:48
   5: <error_chain::State as core::default::Default>::default
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/error-chain-0.12.4/src/lib.rs:687:24
   6: electrs::errors::Error::from_kind
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/error-chain-0.12.4/src/error_chain.rs:269:21
   7: <electrs::errors::Error as core::convert::From<alloc::string::String>>::from
             at /Users/phil/.cargo/registry/src/index.crates.io-6f17d22bba15001f/error-chain-0.12.4/src/error_chain.rs:173:17
   8: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1963:27
   9: electrs::new_index::schema::lookup_txos::{{closure}}
             at src/new_index/schema.rs:1039:23
  10: core::iter::adapters::map::map_try_fold::{{closure}}
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/adapters/map.rs:91:28
  11: core::iter::traits::iterator::Iterator::try_fold
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/traits/iterator.rs:2462:21
  12: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/adapters/map.rs:117:9
  13: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::try_fold
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/adapters/mod.rs:199:9
  14: <core::iter::adapters::GenericShunt<I,R> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/mod.rs:378:13
  15: core::iter::traits::iterator::Iterator::for_each
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/traits/iterator.rs:858:9
  16: <hashbrown::map::HashMap<K,V,S,A> as core::iter::traits::collect::Extend<(K,V)>>::extend
             at /rust/deps/hashbrown-0.14.2/src/map.rs:6433:9
  17: <std::collections::hash::map::HashMap<K,V,S> as core::iter::traits::collect::Extend<(K,V)>>::extend
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/collections/hash/map.rs:3038:9
      <std::collections::hash::map::HashMap<K,V,S> as core::iter::traits::collect::FromIterator<(K,V)>>::from_iter
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/collections/hash/map.rs:3023:13
  18: core::iter::traits::iterator::Iterator::collect
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/traits/iterator.rs:2054:9
      <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter::{{closure}}
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1934:51
  19: core::iter::adapters::try_process
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/adapters/mod.rs:168:17
  20: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1934:9
  21: core::iter::traits::iterator::Iterator::collect
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/iter/traits/iterator.rs:2054:9
  22: electrs::new_index::schema::lookup_txos
             at src/new_index/schema.rs:1034:5
  23: electrs::new_index::schema::Indexer::index
             at src/new_index/schema.rs:330:13
  24: electrs::new_index::schema::Indexer::update::{{closure}}
             at src/new_index/schema.rs:282:67
  25: electrs::new_index::fetch::Fetcher<T>::map
             at src/new_index/fetch.rs:64:13
  26: electrs::new_index::schema::Indexer::update
             at src/new_index/schema.rs:282:9
  27: electrs::run_server
             at src/bin/electrs.rs:65:19
  28: electrs::main
             at src/bin/electrs.rs:147:21


@shesek
Copy link
Collaborator

shesek commented Oct 30, 2024

You need to adjust REGTEST_INITIAL_ISSUANCE_PREVOUT in src/util/transaction.rs for this to work.

The txid of the initial issuance prevout differs based on some chain parameters. Back when I implemented this I couldn't find an easy way to determine it and just used the prevout used with the default chain settings (which might've changed since)

This should be fixed, or at least be made into a CLI argument that can be overridden without recompiling.

@shesek
Copy link
Collaborator

shesek commented Oct 30, 2024

(Based on the error message you got, the REGTEST_INITIAL_ISSUANCE_PREVOUT should be set to cb4953dfe64aba4687d0de08e5ce17d8f7640deeef63be4ac3bac3afdefdfd78 -- perhaps in reversed byte order)

Edit: actually, I believe rust-elements fixed the reversed bytes display issue, so you shouldn't have to reverse it

@philippem
Copy link
Collaborator Author

ok,thanks for tracking this down. A CLI argument would be helpful but may be rarely used.
How did you determine the necessary value of REGTEST_INITIAL_ISSUANCE_PREVOUT ?

@shesek
Copy link
Collaborator

shesek commented Dec 3, 2024

How did you determine the necessary value of REGTEST_INITIAL_ISSUANCE_PREVOUT?

From the error message you posted:

Error(Msg("missing txo [elements]cb4953dfe64aba4687d0de08e5ce17d8f7640deeef63be4ac3bac3afdefdfd78:0"), State { next_error: None, backtrace: InternalBacktrace { backtrace: Some(   0: backtrace::backtrace::libunwind::trace

You can also find it by looking up the prevout of the 2nd transaction in the genesis block:

$ elements-cli getblock $(elements-cli getblockhash 0) 2 | jq .tx[1].vin[0].txid

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

No branches or pull requests

2 participants