Page MenuHomePhabricator

[backport#17261 9/13] refactor: define a UINT256_ONE global constant
ClosedPublic

Authored by majcosta on Oct 9 2020, 16:12.

Details

Summary

Instead of having a uint256 representations of one scattered throughout
where it is used, define it globally in uint256.h

https://github.com/bitcoin/bitcoin/pull/17261/commits/4977c30d59e88a3e5ee248144bcc023debcd895b

Depends on D7855

Partial backport of Core PR17261

Test Plan
ninja all check check-functional

Event Timeline

majcosta requested review of this revision.Oct 9 2020, 16:12

Snippet of first build failure:

[284/434] Building CXX object src/CMakeFiles/server.dir/policy/settings.cpp.o
[285/434] Building CXX object src/CMakeFiles/server.dir/node/psbt.cpp.o
[286/434] Building CXX object src/CMakeFiles/server.dir/pow/daa.cpp.o
[287/434] Building CXX object src/CMakeFiles/server.dir/miner.cpp.o
[288/434] Building CXX object src/CMakeFiles/server.dir/pow/eda.cpp.o
[289/434] Building CXX object src/CMakeFiles/server.dir/rpc/command.cpp.o
[290/434] Building CXX object src/CMakeFiles/server.dir/pow/pow.cpp.o
[291/434] Building CXX object src/CMakeFiles/server.dir/noui.cpp.o
[292/434] Building CXX object src/CMakeFiles/server.dir/node/coinstats.cpp.o
[293/434] Building CXX object src/CMakeFiles/server.dir/pow/aserti32d.cpp.o
[294/434] Building CXX object src/CMakeFiles/server.dir/node/transaction.cpp.o
[295/434] Building CXX object src/CMakeFiles/server.dir/net.cpp.o
[296/434] Building CXX object src/CMakeFiles/server.dir/shutdown.cpp.o
[297/434] Building CXX object src/CMakeFiles/server.dir/timedata.cpp.o
[298/434] Building CXX object src/CMakeFiles/server.dir/script/scriptcache.cpp.o
[299/434] Building CXX object src/CMakeFiles/server.dir/rpc/abc.cpp.o
[300/434] Building CXX object src/CMakeFiles/server.dir/script/sigcache.cpp.o
[301/434] Building CXX object src/CMakeFiles/server.dir/rest.cpp.o
[302/434] Building CXX object src/CMakeFiles/server.dir/rpc/misc.cpp.o
[303/434] Building CXX object src/CMakeFiles/server.dir/rpc/avalanche.cpp.o
[304/434] Building CXX object src/CMakeFiles/server.dir/versionbits.cpp.o
[305/434] Building CXX object src/CMakeFiles/server.dir/rpc/mining.cpp.o
[306/434] Building CXX object src/CMakeFiles/server.dir/rpc/server.cpp.o
[307/434] Building CXX object src/CMakeFiles/server.dir/rpc/net.cpp.o
[308/434] Building C object src/secp256k1/CMakeFiles/sign-bench.dir/src/bench_sign.c.o
[309/434] Building CXX object src/CMakeFiles/server.dir/validationinterface.cpp.o
[310/434] Building C object src/secp256k1/CMakeFiles/verify-bench.dir/src/bench_verify.c.o
[311/434] Building C object src/secp256k1/CMakeFiles/recover-bench.dir/src/bench_recover.c.o
[312/434] Building C object src/secp256k1/CMakeFiles/ecmult-bench.dir/src/bench_ecmult.c.o
[313/434] Building CXX object src/CMakeFiles/server.dir/dummywallet.cpp.o
[314/434] Building CXX object src/CMakeFiles/server.dir/txdb.cpp.o
[315/434] Building C object src/secp256k1/CMakeFiles/internal-bench.dir/src/bench_internal.c.o
[316/434] Building CXX object src/CMakeFiles/server.dir/init.cpp.o
[317/434] Building C object src/secp256k1/CMakeFiles/secp256k1.dir/src/secp256k1.c.o
[318/434] Building CXX object src/test/CMakeFiles/testutil.dir/util/str.cpp.o
[319/434] Linking C static library src/secp256k1/libsecp256k1.a
[320/434] Linking C executable src/secp256k1/ecmult-bench
[321/434] Linking C executable src/secp256k1/internal-bench
[322/434] Linking C executable src/secp256k1/sign-bench
[323/434] Linking C executable src/secp256k1/verify-bench
[324/434] Linking C executable src/secp256k1/recover-bench
[325/434] Building CXX object src/test/CMakeFiles/testutil.dir/util/logging.cpp.o
[326/434] Building CXX object src/test/CMakeFiles/testutil.dir/util/transaction_utils.cpp.o
[327/434] Building CXX object src/CMakeFiles/server.dir/torcontrol.cpp.o
[328/434] Building CXX object src/seeder/CMakeFiles/seeder.dir/dns.cpp.o
[329/434] Building CXX object src/test/CMakeFiles/testutil.dir/util/wallet.cpp.o
[330/434] Building CXX object src/CMakeFiles/server.dir/net_processing.cpp.o
[331/434] Building CXX object src/test/CMakeFiles/testutil.dir/util/blockfilter.cpp.o
[332/434] Building CXX object src/seeder/CMakeFiles/seeder.dir/bitcoin.cpp.o
[333/434] Building CXX object src/seeder/CMakeFiles/seeder.dir/db.cpp.o
[334/434] Building CXX object src/CMakeFiles/server.dir/ui_interface.cpp.o
[335/434] Building CXX object src/test/CMakeFiles/testutil.dir/util/mining.cpp.o
[336/434] Building CXX object src/CMakeFiles/server.dir/txmempool.cpp.o
[337/434] Building CXX object src/CMakeFiles/server.dir/rpc/rawtransaction.cpp.o
[338/434] Building CXX object src/seeder/CMakeFiles/bitcoin-seeder.dir/main.cpp.o
[339/434] Building CXX object src/CMakeFiles/server.dir/rpc/blockchain.cpp.o
[340/434] Building CXX object src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o
[341/434] Building CXX object src/CMakeFiles/server.dir/validation.cpp.o
ninja: build stopped: cannot make progress due to previous errors.
Build build-without-wallet failed with exit code 1

Snippet of first build failure:

[309/485] Building CXX object src/CMakeFiles/bitcoinconsensus.dir/uint256.cpp.o
[310/485] Building C object src/secp256k1/CMakeFiles/verify-bench.dir/src/bench_verify.c.o
[311/485] Building C object src/secp256k1/CMakeFiles/sign-bench.dir/src/bench_sign.c.o
[312/485] Building CXX object src/CMakeFiles/common.dir/rpc/util.cpp.o
[313/485] Building C object src/secp256k1/CMakeFiles/secp256k1.dir/src/secp256k1.c.o
[314/485] Building C object src/secp256k1/CMakeFiles/recover-bench.dir/src/bench_recover.c.o
[315/485] Linking C static library src/secp256k1/libsecp256k1.a
[316/485] Building CXX object src/test/CMakeFiles/testutil.dir/util/logging.cpp.o
[317/485] Linking C executable src/secp256k1/verify-bench
[318/485] Linking C executable src/secp256k1/sign-bench
[319/485] Linking C executable src/secp256k1/recover-bench
[320/485] Installing component secp256k1
-- Install configuration: "RelWithDebInfo"
-- Install component: "secp256k1"
-- Installing: /results/artifacts/lib/libsecp256k1.a
-- Installing: /results/artifacts/include/secp256k1.h
-- Installing: /results/artifacts/include/secp256k1_preallocated.h
-- Installing: /results/artifacts/include/secp256k1_recovery.h
-- Installing: /results/artifacts/include/secp256k1_schnorr.h
[321/485] Building CXX object src/CMakeFiles/bitcoinconsensus.dir/consensus/tx_check.cpp.o
[322/485] Building CXX object src/CMakeFiles/script.dir/script/interpreter.cpp.o
[323/485] Building CXX object src/CMakeFiles/bitcoin-wallet.dir/bitcoin-wallet.cpp.o
[324/485] Building CXX object src/CMakeFiles/bitcoinconsensus.dir/util/strencodings.cpp.o
[325/485] Building CXX object src/test/CMakeFiles/testutil.dir/util/str.cpp.o
[326/485] Building CXX object src/CMakeFiles/script.dir/script/signingprovider.cpp.o
[327/485] Building C object src/secp256k1/CMakeFiles/ecmult-bench.dir/src/bench_ecmult.c.o
[328/485] Linking C executable src/secp256k1/ecmult-bench
[329/485] Building CXX object src/test/CMakeFiles/testutil.dir/util/transaction_utils.cpp.o
[330/485] Building C object src/secp256k1/CMakeFiles/internal-bench.dir/src/bench_internal.c.o
[331/485] Linking C executable src/secp256k1/internal-bench
[332/485] Building CXX object src/CMakeFiles/script.dir/script/descriptor.cpp.o
[333/485] Linking CXX static library src/libscript.a
[334/485] Building CXX object src/CMakeFiles/bitcoin-cli.dir/bitcoin-cli.cpp.o
[335/485] Building CXX object src/test/CMakeFiles/testutil.dir/util/blockfilter.cpp.o
[336/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/coincontrol.cpp.o
[337/485] Building CXX object src/CMakeFiles/bitcoin-tx.dir/bitcoin-tx.cpp.o
[338/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/crypter.cpp.o
[339/485] Building CXX object src/test/CMakeFiles/testutil.dir/util/mining.cpp.o
[340/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/coinselection.cpp.o
[341/485] Building CXX object src/test/CMakeFiles/testutil.dir/util/wallet.cpp.o
[342/485] Building CXX object src/CMakeFiles/server.dir/validation.cpp.o
[343/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/fees.cpp.o
[344/485] Building CXX object src/seeder/CMakeFiles/seeder.dir/bitcoin.cpp.o
[345/485] Building CXX object src/wallet/CMakeFiles/wallet-tool.dir/wallettool.cpp.o
[346/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/db.cpp.o
[347/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/psbtwallet.cpp.o
[348/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletutil.cpp.o
[349/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/load.cpp.o
[350/485] Building CXX object src/seeder/CMakeFiles/seeder.dir/dns.cpp.o
[351/485] Building CXX object src/seeder/CMakeFiles/seeder.dir/db.cpp.o
[352/485] Building CXX object src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o
[353/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/__/interfaces/wallet.cpp.o
[354/485] Building CXX object src/seeder/CMakeFiles/bitcoin-seeder.dir/main.cpp.o
[355/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/scriptpubkeyman.cpp.o
[356/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletdb.cpp.o
[357/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcdump.cpp.o
[358/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/wallet.cpp.o
[359/485] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcwallet.cpp.o
ninja: build stopped: cannot make progress due to previous errors.
Build build-diff failed with exit code 1
deadalnix requested changes to this revision.Oct 9 2020, 16:20
deadalnix added a subscriber: deadalnix.

You need to figure out why the CI is unhappy with this.

src/script/interpreter.cpp
1555 ↗(On Diff #24468)

fix

src/uint256.cpp
71 ↗(On Diff #24468)

Using a unique_ptr would prevent leaks.

This revision now requires changes to proceed.Oct 9 2020, 16:20

would this work as good? I don't see why using the heap is necessary at all, but I'm noob so I might be wrong

deadalnix requested changes to this revision.Oct 9 2020, 22:27
deadalnix added inline comments.
src/uint256.cpp
71 ↗(On Diff #24480)

auto is winning nothing here, because you end up using the constructor anyways. Remove th ctor on the rhs and put the type on the lhs.

This revision now requires changes to proceed.Oct 9 2020, 22:27
This revision is now accepted and ready to land.Oct 10 2020, 13:26