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

last_hash = block.hash.clone(); #4

Open
moaiad1 opened this issue May 6, 2022 · 3 comments
Open

last_hash = block.hash.clone(); #4

moaiad1 opened this issue May 6, 2022 · 3 comments

Comments

@moaiad1
Copy link

moaiad1 commented May 6, 2022

thanks for your efforts and time , I have a warrning when I run cargo as it couldn't read last hash I couldn't figure the issue that cause the problem as well as Failed to add block: InsufficientInputValue' where should the value stored:
please check the result

warning: value assigned to last_hash is never read
--> src/main.rs:63:5
|
63 | last_hash = block.hash.clone();
| ^^^^^^^^^
|
= note: #[warn(unused_assignments)] on by default
= help: maybe it is overwritten before being read?

warning: hash (bin "blockchain") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
Running target/debug/blockchain
Mined genesis block Block[0]: e2937e782fc68a1a0f8f71830f69919136139f6f956fda1e6999f57327070100 at: 1651809036733 with: 1 nonce: 3458
Mined block Block[1]: cb8add22253b754895c232b4ca65f57dcbb42b1ebdb5bd80242e4fdea6b50500 at: 1651809036998 with: 2 nonce: 4312
thread 'main' panicked at 'Failed to add block: InsufficientInputValue', src/main.rs:65:41
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

thanks for the nice topic

@ClementCauffet
Copy link

Hi Moaiad,

Regarding the last_hash warning, the compiler is trying to tell you "you're modifying this variable but do nothing with it after -> you might not need to modify it"

Two solutions for this :

  1. add a third block to the blockchain -> doing so you'll use the variable you just modified
  2. comment this line and erase the "mut" keyword when it's declared above in the code -> never modified so don't need

Regarding the InsufficientInputValue I can't reproduce the warning.
Did you modify the code? Would you mind sharing it if so?

Regards,

Clement

@brandonros
Copy link

brandonros commented Jun 13, 2023

Regarding the InsufficientInputValue I can't reproduce the warning.

I get this as well on a clean git pull

$ cargo run --release
warning: value assigned to `last_hash` is never read
  --> src/main.rs:63:5
   |
63 |     last_hash = block.hash.clone();
   |     ^^^^^^^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_assignments)]` on by default

warning: `blockchain-in-rust` (bin "blockchain") generated 1 warning
    Finished release [optimized] target(s) in 0.01s
     Running `target/release/blockchain`
Mined genesis block Block[0]: 3195234a06cae70ced0cfa30a58c0039fe50bda3ec577d4f185ac19065a90800 at: 1686695216394 with: 1 nonce: 1942
Mined block Block[1]: 54f7007a87674707a068a0ac7c3dcd2291601b3e93855cefa680ce097a680b00 at: 1686695216396 with: 2 nonce: 5318
thread 'main' panicked at 'Failed to add block: InsufficientInputValue', src/main.rs:65:41
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I added some logging:

Transaction { inputs: [Output { to_addr: "Alice", value: 50 }], outputs: [Output { to_addr: "Alice", value: 360 }, Output { to_addr: "Bob", value: 12 }] }
input_value = 50 output_value = 372
thread 'main' panicked at 'Failed to add block: InsufficientInputValue', src/main.rs:65:41

@brandonros
Copy link

image

In the video it's 36, in the code it is 360. Guessing it's a typo.

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

3 participants