nervosnetwork / fiber

16 stars 8 forks source link

Add unit test to check the validitiy of commitment transaction #39

Closed contrun closed 3 months ago

contrun commented 3 months ago

This PR partly resolves https://github.com/contrun/ckb-pcn-node/issues/26. It tests that we can broadcast the commitment transaction to the network (i.e. commitment transaction is valid). We need also to create a test which consumes the comitment tx output (e.g.with revocation key).

The notable changes to this PR are:

  1. A mock chain actor is created to verify transaction validity. Every transaction send to this actor via SendTx will be verified. If this transaction is invalid then the response to TraceTx request will return Status::Rejected. This is very useful to quickly check the validity of any transactions. In this PR, I used this infrastructure to test the commitment transaction can indeed consume the funding cell.
  2. There is now a unit test to check the validity of the commitment transaction (in the sense that it can be posted to the network). As a side effect, the bug of not correctly setting witnesses to the commitment transaction is now fixed.
  3. We now have a few more events that will be made visible to outside, including CommitmentSignaturePending which tells the owner it is his turn to sign a commitment transaction (this makes it quite easy to solve https://github.com/contrun/ckb-pcn-node/issues/27,. RemoteCommitmentSigned to signify a new commitment is signed by the remote.
  4. Move the module chain in ckb to ckb_chain. ckb/chain was previously used to obtain contract (like commitment lock outpoint) information. It seems that only using ckb_chain to interact with the chain is more appropriate.