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

Multisigtool consolidate multisig unspent #1529

Merged
merged 3 commits into from
Oct 1, 2019

Conversation

iFoggz
Copy link
Member

@iFoggz iFoggz commented Sep 16, 2019

This is one tool I've created to consolidate multi-sig utxos and allow multiple wallets to sign it if need be. Currently we keep track of utxos for our large ones in foundation. We have been getting donations various ways such as side staking. This tool allows us to consolidate small utxos into a single larger one with ease.

Features:

  • Scan a block range for utxos matching user choosen address
  • Allow a max inputs to be set by user but have a firm max set in code to prevent hex transactions being longer then the rpc can handle in length
  • Estimate the sizes and fees of the transaction before required signatures are needed to provide correct fees to miner of the block containing the tx.
  • Support various multisig types of address: 2 of 3, 3 of 4, 3 of 5, 4 of 5
  • Provide information about the utxos the rpc has found and amounts involved.

This creates a raw transaction with near calculations of the potential size of the hex and serialization of the transaction.

I've taken time to learn about the transaction hex formats and where I could make a good formula to buffer the byte size only a little for variances in serialization and hex process.

2 of 3 multisig test:

"Block Start": 1024100,
"Block End": 1024192,
"Amount of Inputs": 40,
"Total GRC In": 400.00000000,
"Fee": 120000,
"Output Amount": 399.99880000,
"Estimated signed hex size": 23862, (+132)
"Estimated Serialized size": 11931, (+66)

signed hex size is 23730
serialized size is 11865

---

3 of 4 multisig test:

"Block Start": 1024100,
"Block End": 1024192,
"Amount of Inputs": 30,
"Total GRC In": 300.00000000,
"Fee": 130000,
"Output Amount": 299.99870000,
"Estimated signed hex size": 24382, (+136)
"Estimated Serialized size": 12191, (+68)

signed hex size is 24246 
serialized size is 12123

---

3 of 5 multisig test:
Block Start": 1024100,
"Block End": 1024192,
"Amount of Inputs": 30,
"Total GRC In": 300.00000000,
"Fee": 140000,
"Output Amount": 299.99860000,
"Estimated signed hex size": 26422, (+128)
"Estimated Serialized size": 13211, (+64)

signed hex size is 26294
serialized size is 13147

-----

4 of 5 multisig test:
"Block Start": 1024100,
"Block End": 1024192,
"Amount of Inputs": 20,
"Total GRC In": 200.00000000,
"Fee": 110000,
"Output Amount": 199.99890000,
"Estimated signed hex size": 20582, (+144)
"Estimated Serialized size": 10291, (+72)

signed hex size is 20438
serialized size is 10219

As you can see the size is very close to the end result This will keep fees correct in most cases and in some cases cause a small fee increase for the transaction but this is pretty close without factoring the signatures in since we are just creating the raw transaction for the multisig key holders to sign.

I plan to make new tools in future to support the multisig addresses more and the future users of multisig on the network.

Let me know where you want changes. there is lots of commenting but I thought It would be important for those who go in the area understand the reasoning behind the code and calculations

@iFoggz
Copy link
Member Author

iFoggz commented Sep 30, 2019

as soon as this is pushed in i can then write the next tool in the multisig chest.

Copy link
Member

@jamescowens jamescowens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Member

@cyrossignol cyrossignol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Great tool... It looks like this could implicitly support types where m == n (for example, 2-of-2) and other variations by calling it with a higher multi-sig-type, but the estimations will be a little off. I wonder if there's a generic way to express that...

For the future, though. This looks like it does the job for now.

@iFoggz
Copy link
Member Author

iFoggz commented Oct 1, 2019

u want support for 2 of 2 and 3 of 3? if you have alll private keys for a said address your wallet would pick it up and u can send funds like a normal transaction for a single address in wallet. it would show in balance and would show in inputs in coin control

@jamescowens jamescowens merged commit 9612a98 into gridcoin-community:development Oct 1, 2019
@iFoggz
Copy link
Member Author

iFoggz commented Oct 1, 2019

Screenshot from 2019-10-01 08-25-45
heres a 3 of 3 in my wallet.

jamescowens added a commit that referenced this pull request Oct 22, 2019
Added
 - Add testnet desktop launcher action for Linux #1516 (@caraka)
 - Shuffle vSideStakeAlloc if necessary to support sidestaking to more than 6 destinations #1532 (@jamescowens)
 - New Superblock format preparations for Fern #1526, #1542 (@jamescowens, @cyrossignol)
 - Multisigtools
   - Consolidate multisig unspent #1529 (@iFoggz)
   - Scanforunspent #1547 (@iFoggz)
   - consolidatemsunspent and scanforunspent bug fix #1561 (@iFoggz)
 - New banning misbehavior handling and Peers Tab on Debug Console #1537 (@jamescowens)
 - Reimplement getunconfirmedbalance rpc #1548 (@jamescowens)
 - Add CLI switch to display binary version #1553 (@cyrossignol)

Changed
 - Select smallest coins for contracts #1519 (@iFoggz)
 - Move some functionality from miner to SelectCoinsForStaking + Respect the coin reserve setting + Randomize UTXO order #1525 (@iFoggz)
 - For voting - if url does not contain http then add it #1531 (@iFoggz)
 - Backport newer serialization facilities from Bitcoin #1535 (@cyrossignol)
 - Refactor ThreadSocketHandler2() Inactivity checks #1538 (@iFoggz)
 - Update outdated checkpoints #1539 (@barton2526)
 - Change needed to build Gridcoin for OSX using homebrew #1540 (@Git-Jiro)
 - Optimize scraper traffic for expiring manifests #1542 (@jamescowens)
 - Move legacy neural vote warnings to debug log level #1560 (@cyrossignol)
 - Change banlist save interval to 5 minutes #1564 (@jamescowens)
 - Change default rpcconsole.ui window size to better support new Peers tab #1566 (@jamescowens)

Removed
 - Remove deprecated RSA weight and legacy kernel #1507 (@cyrossignol)

Fixed
 - Clean up compiler warnings #1521 (@cyrossignol)
 - Handle missing external CPID in client_state.xml #1530 (@cyrossignol)
 - Support boost 1.70+ #1533 (@iFoggz)
 - Fix diagnostics failed to make connection to NTP server #1545 (@Git-Jiro)
 - Install manpages in correct system location #1546 (@Git-Jiro)
 - Fix ability to show help and version without a config file #1553 (@cyrossignol)
 - Refactor QT UI variable names to be more consistent, Fix Difficulty default #1563 (@barton2526)
 - Fix two regressions in previous UI refactor #1565 (@barton2526)
 - Fix "Owed" amount in output of "magnitude" RPC method #1569 (@cyrossignol)
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

Successfully merging this pull request may close these issues.

3 participants