Code Monkey home page Code Monkey logo

magicalcryptowallet's Introduction

IMPORTANT

This was a temprorary repository for development purposes. The work is being continued under the real repository: https://github.com/zkSNACKs/WalletWasabi

MagicalCryptoWallet

Windows Linux & OSX
Windows build status Linux & OSX build status

Roadmap

Goal: Stability, feature minimalization.

It is expected for the proposed timeline to take roughly 1.5 times longer.

1. Wallet Stage

  • 1. Wallet Back End. 2 weeks. NBitcoin, Bitcoin Core RPC, ASP.NET. Build back end.

  • 2. Small Tor Library. 1 week. Tor, .NET Core, cross platform. Build a small Tor library based on DotNetTor, that removes features those are unrelated to the wallet and makes the rest more stable.

  • 3. Key Manager. 1 week. NBitcoin. Build a new, high performance key manager with accounts, labelling, etc...

  • 4. Wallet Client. 1 month. NBitcoin. Build a high performance client that can work with the new back end, which is built for client side filtering.

    Depends on:

    • ALL previous items

2. Privacy Stage

  • 5. ZeroLink Research. 1 month. Bitcoin privacy, cryptography. Research ZeroLink, based on technological advancements.

  • 6. ZeroLink Coordinator. 2 weeks. NBitcoin, Bitcoin Core RPC. Revise the ZeroLink Coordinator code based on ZeroLink v2 Revision.

    Depends on:

    • ZeroLink v2 Revision
  • 7. ZeroLink Client. 2 weeks. NBitcoin. Revise the ZeroLink Client code based on ZeroLink v2 Revision.

    Depends on:

    • ZeroLink v2 Revision
    • ZeroLink Coordinator

3. User Experience Stage

  • 8. GUI. 1 month. Electron, front end, Bitcoin. Redesign the user experience and build it.

    Depends on:

    • ALL previous items

4. Deployment Stage

  • 9. Documentation. 1 week. Bitcoin. Create documentation.

    Depends on:

    • ALL previous items
  • 10. Internal Testing. 2 weeks. Bitcoin or .NET or front end. Test the software and fix the bugs (if there is any haha).

    Depends on:

    • ALL previous items, except Documentation
  • 11. Deploy To Mainnet. 2 weeks. .NET Core, ASP.NET Core deployment. Deploy the software to Bitcoin Mainnet.

    Depends on:

    • ALL previous items, except Documentation
  • 12. Mainnet Beta Testing. 2 weeks. It's rather a marketing phase. The goal is to get at least 1 round done with > 100 user.

    Depends on:

    • ALL previous items

magicalcryptowallet's People

Contributors

lontivero avatar molnard avatar nopara73 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

magicalcryptowallet's Issues

Improve naive exchange rate query

Backend answers for exchange rates in a naive way.

Function to improve: BlockchainController.GetExchangeRatesAsync.

Outline of performance increases:

// ToDo: Implement caching for instant answers.
// ToDo: Implement redundancy, call another API if SmartBit fails, if that fails, call another one.

Add reorg test for IndexFilterBuilder

I added Nicolas's NodeBuilder (the one that's used in NTumbleBit, so it works on Linux and Windows) and I added some basic tests for the IndexFilterBuidler:

dc5d694#diff-4b985814ee76663ced0a1d3899107e09R202

More tests are appreciated, especially a reorg test. I can test it with regtest rpc's invalidateblock, so I made sure reorgs work properly, yet unit test may be also needed here for further code changes.

Reorgs will work properly after this PR is merged, now they only half working: #48

Add functionalities and xml comments to Height struct

Functionalities:
Increment
Decrement
operator +
operator -

And basically any operator that you can figure and makes sense.

For this you must understand the Height struct. You may want to start with the xml comments, that helps you in the understanding. It's a quite handy class. It's basically an int, plus it has two special values: Height.Unknown and Height.Mempool

Add RPCs to NBitcoin

Go through what RPC-s are used in the tesoftware and if the RPC is used manually with SendCommandAsync, then implement and add them to NBitcoin. Try doing full job, ergo don't do things, like throwing away an RPC response, because that doesn't seem relevant.

Also add tests.

Implement Guard.InRangeAndNotNull to long

It's implemented to int-s only at the moment.
Maybe it could even be implemented for double, decimal, Money and whatever other often used types there are that makes sense.

Make sure MemPoolService.TransactionHashes don't overflow

In MemPoolBehavior:

foreach (var inv in invPayload.Inventory.Where(inv => inv.Type.HasFlag(InventoryType.MSG_TX)))
{
	// if we already have it continue;
	// ToDo: Make sure TransactionHashes don't overflow
	if(!MemPoolService.TransactionHashes.Add(inv.Hash))
	{
		continue;
	}

	payload.Inventory.Add(inv);
}

Interlocked.Read for int?

Whenever I'm using Interlocked, I always end up using it with a long, due to it's the only type that Interlocked.Read() is implemented for.

Is it ok to write an extension method for int, too?

Implement Client Services

Moving on to client implementation there are different services/jobs the client must implement, some of it can be done without backend, some of it cannot, some of it which can be brought over from HiddenWallet, some of it which cannot.

  • Connection maintainer service to the Bitcoin peer to peer network.
  • Tracker/Indexer service, that tracks balances, transactions, etc...
  • Mempool service.
  • Block downloading service.
  • Block store service.
  • Filter downloading service.
  • FeeRate service - not sure this is needed.

The services are also not terribly well thought out by me, I roughly sketched up what HiddenWallet does, we'll make decisions in implementation time, because it was quite slow (though it's possible, because of the millions of blocks parsed and indexed real time.) I'll try to make sure it'll be a cleaner design this time.

Add `waitforblock` to Golomb-Rice filtering PR

#38

Right now, I'm just periodically asking for block from the RPC, and if the block height doesn't exist, then I wait 1 sec and continue. With waitforblock it'd be more elegant.

Current code:

Block block = null;
try
{
	block = await RpcClient.GetBlockAsync(height);
}
catch (RPCException) // if the block didn't come yet
{
	// ToDO: If this happens, we should do `waitforblock` RPC instead of periodically asking.
	// In that case we must also make sure the correct error message comes.
	await Task.Delay(1000);
	continue;
}

Handle reorgs properly in Golomb-Rice filtering PR

#38

Right now, when a block is queried from the RPC and if its prevhash is not the hash of our last index's hash, then we delete the last index and continue. The problem, we need to keep track of an utxoset, too, so we have to reverse the last operation from that, too. Which is a pain in the ass. The current code:

// ToDo: IMPORTANT! The Bech32UtxoSet MUST be recovered to its previous state, too!
if (prevHash != block.Header.HashPrevBlock) // reorg
{
	using (await IndexLock.LockAsync())
	{
		Index.RemoveAt(Index.Count - 1);
	}

	// remove last line
	var lines = File.ReadAllLines(IndexFilePath);
	File.WriteAllLines(IndexFilePath, lines.Take(lines.Length - 1).ToArray());
	continue;
}

Improve naive fee estimation

Backend currently estimates fees in a naive way. Avoiding redundant RPC commands can lower resources as much as 99%.

Function to improve: BlockchainController.GetFeesAsync.

Outline of performance increases:

// ToDo: This is the most naive way to implement this.
// 1. Use the sanity check that under 5 satoshi per bytes should not be displayed.
// 2. Use the RPCResponse.Blocks output to avoid redundant RPC queries.
// 3. Implement caching.

Fix encrypted logging

I have a general encrypy/decrypt function: StringCypher.

It fails once in a while. Appveyor Windows logs:

[xUnit.net 00:00:06.4325447]     CipherTests [FAIL]
[xUnit.net 00:00:06.4328704]       Assert.Throws() Failure
[xUnit.net 00:00:06.4329209]       Expected: typeof(System.Security.Cryptography.CryptographicException)
[xUnit.net 00:00:06.4329547]       Actual:   (No exception was thrown)
[xUnit.net 00:00:06.4338087]       Stack Trace:
[xUnit.net 00:00:06.4349705]         C:\projects\magicalcryptowallet\MagicalCryptoWallet.Tests\CryptoTests.cs(44,0): at MagicalCryptoWallet.Tests.CryptoTests.CipherTests()
Failed   CipherTests
Error Message:
 Assert.Throws() Failure
Expected: typeof(System.Security.Cryptography.CryptographicException)
Actual:   (No exception was thrown)
Stack Trace:
   at MagicalCryptoWallet.Tests.CryptoTests.CipherTests() in C:\projects\magicalcryptowallet\MagicalCryptoWallet.Tests\CryptoTests.cs:line 44

Possible way to reproduce it:

  1. Write a test that assert throwing the CryptographicException many times and hope it'll fail once in a while, too.

Add Guard.Correct pattern

It's a straightforward improvement I believe.

public HdPubKey GetReceiveKey(string label)
{
// ToDo, put this correction pattern into the Guard class: Guard.Correct(string ...)
if(string.IsNullOrWhiteSpace(label))
{
label = "";
}
else
{
label = label.Trim();
}
// Make sure there's always 21 clean keys generated and indexed.
while (KeyManager.GetKeys(KeyState.Clean, false).Count() < 21)
{
KeyManager.GenerateNewKey("", KeyState.Clean, false);
}
var ret = KeyManager.GetKeys(KeyState.Clean, false).RandomElement();
ret.Label = label;
return ret;
}

Add OSX and Linux CI to NBitcoin

It'd be really good if CI would be done on different platforms in NBitcoin. I'm afraid, there'd be some really nasty issues and it'd take a lot of time, I'm not sure it worth it. Maybe try spending 3 days on it and if the tests still don't pass, then leave it?

CryptographicException ruining the Debug log

@lontivero In the AuthenticateMessageTest there is 10000 of this message if you run the tests in debug mode in Visual Studio: Exception thrown: 'System.Security.Cryptography.CryptographicException' in MagicalCryptoWallet.dll.

Is there any way to make it not write the exception to Debug output that without turning off the test?
If there is no, I think we should lower the cycle to run 3 times only.

Utilize 100 blocks maturity in IndexBuilderService

  • ActionHistoryHelper should be turned off while initial index building is in process. It be turned on from best height - 100 blocks maturity.
  • Similarly any Index reorgs should not happen initial index building phase. Eg, this if condition should check for IIB (Initial Index Building, I'm abbreviating it similarly to IBD- Initial Blockchain Downloading.)
// In case of reorg:
if (prevHash != block.Header.HashPrevBlock)
{
	Logger.LogInfo<IndexBuilderService>($"REORG Invalid Block: {prevHash}");
	// 1. Rollback index
  • ActionHistoryHelper should drop its oldest history record, when it hits the number 100. (To prevent memory leak.)

Add reorg test for Bech32UtxoSetHistory

Utxo History is reorgable until 100 blocks. This is currently not tested. The reorg test only tests the Index reorg (which is currently reorgable until forever)

The UTXO history reorgability was fully implemented here: 0b5ce8a

Cache data directory on appveyor and travis

It will speed up the tests.
On travis the datadir is in home .magicalcryptowallet.
On appveyor the datadir is in appdata MagicalCryptoWallet.

I intend to form the folder structure of this working directory the following way:
datadir/{project name}
For example for the backend project on Windows it'll be: MagicalCryptoWallet\Backend.
Tests are even more structured, I plan to put every test data into different directory, eg:
MagicalCryptoWallet\Tests\FooTestAsync.

Think about platform for GUI

The main problem is, there is no cross platform GUI for .NET Core, like Windows Forms or WPF.

HiddenWallet uses Electron, which is basically a "lean" chrome browser. Therefore the architecture looks like having a local http api running (daemon written in ASP.NET Core) and the GUI was written in HTML/CSS/JavaScript, which communicates with the daemon.

Since then, Electron may have been somehow integrated into .NET Core with Electron.NET: https://github.com/ElectronNET/Electron.NET so if we want to keep working with it we must go with Electron.NET.

To drop it here, there is also another framework called Avalonia, which is "a WPF-inspired cross-platform XAML-based UI framework." https://github.com/AvaloniaUI/Avalonia
This had no documentation at the time, but now it has decent amount. Also it looks like much more popular than Electron, so this may be a better choice?

Related issue: zkSNACKs/WalletWasabi#96

Make Backend work with RegTest

Or just simulate to work with it (eg. fees cannot be queried.)

The way I'd go about it:

  1. Change to regtest in the Backend's Config.json.
  2. Start bitcoind in regtest.
  3. Start backend and go to swagger.
  4. Go through all the requests in swagger.
  5. Fix what's breaking.

Timeout if tests run forever

Test name: TestServicesAsync. Have to do according to the ToDos.

while (Interlocked.Read(ref _nodeCount) < 3)
{
	await Task.Delay(100); // ToDo: timeout after a few minutes
}

while (Interlocked.Read(ref _mempoolTransactionCount) < 7)
{
	await Task.Delay(100); // ToDo: timeout after a few minutes
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.