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

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

Merged
merged 30 commits into from
Jun 7, 2024

Conversation

contrun
Copy link
Collaborator

@contrun contrun commented Jun 4, 2024

This PR partly resolves #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 Automatically generate CommitmentSigned responses in channel establishment #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.

@contrun contrun force-pushed the test-commitment-tx-validity branch from 4336f08 to 9037cc4 Compare June 4, 2024 18:50
@contrun contrun force-pushed the test-commitment-tx-validity branch from 734e170 to 5d1bb6e Compare June 4, 2024 21:22
return Ok(());
}
let current_capacity: u64 = output.capacity().unpack();
let capacity = request.local_amount + current_capacity;
Copy link
Collaborator

Choose a reason for hiding this comment

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

emm, we need to care about UDT on this part.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. We should also take care of UDT here, which would depend on your work. So, for now, we'd better leave this as a known issue.

@quake quake merged commit 1b22666 into main Jun 7, 2024
8 checks passed
@contrun contrun mentioned this pull request Jun 10, 2024
@quake quake deleted the test-commitment-tx-validity branch June 14, 2024 06:30
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.

Add unit test for commitment transaction
3 participants