Blockstream / electrs

An efficient re-implementation of Electrum Server in Rust
MIT License
320 stars 131 forks source link

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

Open philippem opened 2 weeks ago

philippem commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

(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