Capitalisk / ldpos-commander

CLI client for LDPoS blockchains
MIT License
3 stars 2 forks source link

Project specification #1

Closed jondubois closed 3 years ago

jondubois commented 3 years ago

Project description

A REPL command-line client which allows a user to interact with an LDPoS blockchain.

Overview

LDPoS is a simple and lightweight DPoS blockchain which uses a hash-based signature scheme (Lamport OTS with Merkle Signature Scheme) which is believed to be resistant to potential quantum computing attacks. LDPoS has the following features:

Deliverables

Background work

The ldpos-client-js library has already been added as a dependency to this project and has been published to npm under the package name ldpos-client. Also published on npm here: https://www.npmjs.com/package/ldpos-client

A mocha integration test suite has been setup.

The ldpos-client library already has most of the functionality related to signing and verifying transactions but additional functionality will be added to load data from the bockchain node.

To understand how the ldpos-client library works, check out this sample client: https://github.com/Leasehold/ldpos-client-js/blob/master/scripts/sample-client.js. You can run it with the command node sample-client.js 34.227.22.98. Feel free to use the node at 34.227.22.98 testing; it's a mock/dummy node (it's missing the database layer); it's not forging or processing transactions yet but it can receive and respond to certain actions and should be enough to get started.

It may also help to git clone this repo https://github.com/Leasehold/ldpos-chain and run the tests (they also make use of the JS client) in order to get a broader idea of the kinds of functionality which needs to be supported.

Check the issues section of this repo for more specific issues and feel free to raise new ones.

Additional requirements

jondubois commented 3 years ago

@bartekus I added remaining methods which you can now use: https://github.com/Leasehold/ldpos-client-js/blob/c2ef83dfc949a0202a34de6d23c94897654f11e0/index.js#L453-L546

bartekus commented 3 years ago

Hey Jon,

Is there a specific node version I should be running? On:

❯ node -v
v15.4.0

while being able to ping 34.227.22.98 no problem, running the sample-client is failing to connect:

❯ node sample-client 34.227.22.98
/Users/bart/Dev/Leasehold/ldpos-client-js/sc-adapter.js:22
      throw new Error(
            ^

Error: Failed to connect because of error 1006: Socket hung up
    at SCAdapter.connect (/Users/bart/Dev/Leasehold/ldpos-client-js/sc-adapter.js:22:13)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async LDPoSClient.connect (/Users/bart/Dev/Leasehold/ldpos-client-js/index.js:80:7)
    at async createClient (/Users/bart/Dev/Leasehold/ldpos-client-js/index.js:586:5)
    at async /Users/bart/Dev/Leasehold/ldpos-client-js/scripts/sample-client.js:9:16

On the other hand:

❯ npm run test

> ldpos-chain@1.0.3 test
> mocha --reporter spec --timeout 40000 --slow 40000

  DEX API tests
    module state
      ✓ should expose an info property
      ✓ should expose an alias property
      ✓ should expose an events property
    module actions
      getMultisigWalletMembers action
        ✓ should return an array of member addresses
        ✓ should throw a MultisigAccountDidNotExistError if the multisig wallet address does not exist
      getMinMultisigRequiredSignatures action
        ✓ should return the number of required signatures
        ✓ should throw an AccountDidNotExistError if the wallet address does not exist
        ✓ should throw an AccountWasNotMultisigError if the account is not a multisig wallet
      getOutboundTransactions action
        ✓ should return an array of transactions sent from the specified walletAddress
        ✓ should return transactions which are more recent than fromTimestamp
        ✓ should limit the number of transactions based on the specified limit
        ✓ should return an empty array if no transactions can be matched
      getInboundTransactionsFromBlock action
        ✓ should return an array of transactions sent to the specified walletAddress
        ✓ should return an empty array if no transactions match the specified blockId
        ✓ should return an empty array if no transactions match the specified walletAddress
      getOutboundTransactionsFromBlock action
        ✓ should return an array of transactions sent to the specified walletAddress
        ✓ should return transactions with a valid signatures property if transaction is from a multisig wallet
        ✓ should return an empty array if no transactions match the specified blockId
        ✓ should return an empty array if no transactions match the specified walletAddress
      getLastBlockAtTimestamp action
        1) should return the highest block which is below the specified timestamp
        ✓ should throw a BlockDidNotExistError error if no block can be found before the specified timestamp
      getMaxBlockHeight action
        ✓ should return the height of the block as an integer number
      getBlocksBetweenHeights action
        ✓ should return blocks whose height is greater than fromHeight and less than or equal to toHeight
        ✓ should return blocks whose height is greater than fromHeight and less than or equal to toHeight
        ✓ should return an empty array if no blocks are matched
      getBlockAtHeight action
        ✓ should expose a getBlockAtHeight action
        ✓ should throw a BlockDidNotExistError if no block could be matched
      postTransaction action
        ✓ should accept a prepared (signed) transaction object as argument
    module events
      ✓ should trigger bootstrap event after launch
      ✓ should expose a chainChanges event

  Functional tests
    block forging
      with a single registered delegate
        without any transactions
          ✓ should forge correct number of valid blocks based on forging interval
        with transactions
          ✓ should forge valid blocks which contain the correct number of transactions
    block processing
      when processing blocks which contain valid sig transfer transactions
        ✓ should process all valid transactions within blocks and correctly update account balances
      when processing a block multiple times which contains sig transactions due to database connection failure
Error: Failed to upsert block because of simulated database connection issue
    at DAL.chainModule.dal.upsertBlock (/Users/bart/Dev/Leasehold/ldpos-chain/test/functional-tests.js:315:19)
    at LDPoSChainModule.processBlock (/Users/bart/Dev/Leasehold/ldpos-chain/index.js:1062:20)
    at async /Users/bart/Dev/Leasehold/ldpos-chain/index.js:2169:13
        ✓ should update the state in an idempotent way
      when processing blocks which contain valid multisig transfer transactions
        ✓ should process all valid transactions within blocks and correctly update account balances
      when processing a block multiple times which contains multisig transactions due to database connection failure
Error: Failed to upsert block because of simulated database connection issue
    at DAL.chainModule.dal.upsertBlock (/Users/bart/Dev/Leasehold/ldpos-chain/test/functional-tests.js:504:19)
    at LDPoSChainModule.processBlock (/Users/bart/Dev/Leasehold/ldpos-chain/index.js:1062:20)
    at async /Users/bart/Dev/Leasehold/ldpos-chain/index.js:2169:13
        ✓ should update the state in an idempotent way
    transfer transaction
      valid transfers
        ✓ should update account balances
      invalid transfer
        ✓ should throw an error
    vote transaction
      valid vote
        ✓ should update the top delegate list
      invalid vote; already voted for delegate
        ✓ should send back an error
      invalid vote; exceeded maximum number of votes per account
        ✓ should send back an error
    unvote transaction
      valid unvote
        ✓ should update the top delegate list
      invalid unvote; unvoting an address which the voter is not voting for
        ✓ should send back an error
    registerMultisigWallet transaction
      valid registerMultisigWallet
        ✓ should convert sig account into multisig wallet
      multiple valid registerMultisigWallet
        ✓ should support re-registering an existing multisig wallet with a different set of member addresses
      invalid registerMultisigWallet
        ✓ should send back an error
    registerSigDetails transaction
      valid registerSigDetails
        ✓ should add all the necessary keys on the account
      invalid registerSigDetails
        ✓ should send back an error
    registerMultisigDetails transaction
      valid registerMultisigDetails
        ✓ should add all the necessary keys on the account
      invalid registerMultisigDetails
        ✓ should send back an error
    registerForgingDetails transaction
      valid registerForgingDetails
        ✓ should add all the necessary keys on the account
      invalid registerForgingDetails
        ✓ should send back an error

  Public API tests
    module actions
      getAccount action
        ✓ should return an account object

  52 passing (7m)
  1 failing

  1) DEX API tests
       module actions
         getLastBlockAtTimestamp action
           should return the highest block which is below the specified timestamp:
     BlockDidNotExistError: No block existed with timestamp less than or equal to 31000
      at DAL.getLastBlockAtTimestamp (test/utils/dal.js:286:19)
      at Object.handler (index.js:317:27)
      at Context.<anonymous> (test/dex-api-tests.js:579:71)
      at processImmediate (node:internal/timers:463:21)

npm ERR! code 1
npm ERR! path /Users/bart/Dev/Leasehold/ldpos-chain
npm ERR! command failed
npm ERR! command sh -c mocha --reporter spec --timeout 40000 --slow 40000

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bart/.npm/_logs/2021-01-24T04_59_26_268Z-debug.log
jondubois commented 3 years ago

@bartekus You can try pulling the latest master branch again. I was fixing some stuff today. Also I took down the test node temporarily (the one which sample client connects to). I'll try to get it back running in a few hours.

jondubois commented 3 years ago

@bartekus About node.js version. I'm using v11.13.0 but I'll try to get it working with newer versions too. I haven't tested it with newer versions.

jondubois commented 3 years ago

@bartekus OK I launched the test node. It's actually running as part of a small (2 node network). I might restart the test node from time to time because it's using an in-memory (mock) adapter which is not optimized... Try not to send too many transactions to it.

jondubois commented 3 years ago

I made a few transactions already so there is some data in there.

jondubois commented 3 years ago

I made some changes to the client constructor to make it simpler to instantiate.

https://github.com/Leasehold/ldpos-client-js/blob/c63ada04dd640078d30fef6cd528065996cac03d/scripts/sample-client.js#L8-L16