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

feat: Implement an in-process test core node with celestia-app and custom state #824

Merged
merged 15 commits into from
Oct 3, 2022

Conversation

evan-forbes
Copy link
Member

This PR is based of the network tests in the cosmos-sdk. Those tests are focused on running multiple nodes, while this test only runs a single node validator. This node also has the full access to change the consensus parameters and the full tendermint config. This is needed to to have block times shorter than 1 second. There is also discussion to modify the sdk code to only be a mock, where we need to run a full in process node to include any changes to tendermint and to not have to apply those same changes to the new upcoming mock node in the sdk.

While this does have extra features and a built in API, it does have a lot of duplicate features to our own wrapper around the linked above network tests. Eventually we should replace the usage of that code in the integrations tests with this code.

closes #770

@evan-forbes evan-forbes added C: Celestia app testing items that are strictly related to adding or extending test coverage labels Sep 30, 2022
@evan-forbes evan-forbes self-assigned this Sep 30, 2022
@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2022

Codecov Report

Merging #824 (66f7d9d) into main (2808660) will decrease coverage by 16.80%.
The diff coverage is 67.54%.

@@             Coverage Diff             @@
##             main     #824       +/-   ##
===========================================
- Coverage   42.00%   25.20%   -16.81%     
===========================================
  Files          42       75       +33     
  Lines        4378     9225     +4847     
===========================================
+ Hits         1839     2325      +486     
- Misses       2390     6681     +4291     
- Partials      149      219       +70     
Impacted Files Coverage Δ
testutil/testnode/node_interaction_api.go 60.22% <60.22%> (ø)
testutil/testnode/node_init.go 66.48% <66.48%> (ø)
testutil/testnode/full_node.go 72.36% <72.36%> (ø)
testutil/testnode/rpc_client.go 81.81% <81.81%> (ø)
pkg/shares/shares.go 22.85% <0.00%> (-77.15%) ⬇️
pkg/shares/parse_sparse_shares.go 77.33% <0.00%> (-2.67%) ⬇️
x/payment/types/payfordata.go 76.33% <0.00%> (-0.36%) ⬇️
app/app.go 6.49% <0.00%> (-0.07%) ⬇️
pkg/inclusion/paths.go 100.00% <0.00%> (ø)
x/payment/types/tx.pb.go 18.04% <0.00%> (ø)
... and 39 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@rach-id rach-id left a comment

Choose a reason for hiding this comment

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

utAck. Awesome stuff 🚀 Would be really helpful for QGB tests 🔥

}

cparams := types.DefaultConsensusParams()
cparams.Block.TimeIotaMs = 1
Copy link
Member

Choose a reason for hiding this comment

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

[Non Blocking][Question]
Doesn't it make sense to take the consensus params as a parameter for more flexibility?
Especially the block time, I guess it makes sense to give the user the abilitiy to change it.
Then, we can for example check if the provided consensus params are null, we initialize using the default ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea 903bc0b

var latestHeight int64
for {
select {
case <-timeout.C:
Copy link
Member

Choose a reason for hiding this comment

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

[Non Blocking][Suggestion]
Doesn't it make sense also to check if the root context was cancelled or done?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 96cec2a

ticker := time.NewTicker(time.Second)
defer ticker.Stop()

timeout := time.NewTimer(t)
Copy link
Member

Choose a reason for hiding this comment

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

[Non Blocking][Suggestion]
Doesn't it make sense to use the context with timeout? to also propagate timeouts if something happens?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, might as well 96cec2a


// create a random msg per row
pfd, err := payment.BuildPayForData(
context.TODO(),
Copy link
Member

Choose a reason for hiding this comment

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

[Non Blocking][Question]
Why use the TODO context when we have a context passed func (c *Context) PostData...?

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch! wrote this when we didn't yet have contexts 95529af

func RandomValidNamespace() namespace.ID {
for {
s := tmrand.Bytes(8)
if bytes.Compare(s, appconsts.MaxReservedNamespace) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

[Non Blocking][Question]
This one is used to create a PFD. Shouldn't we also check if the namespace is not the ns of evidence or?

Copy link
Collaborator

Choose a reason for hiding this comment

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

MaxReservedNamespace is greater than the namespace used for transactions, intermediate state roots, or evidence so this conditional will evaluate to false if s matches any of those namespaces.

In other words, the returned s should only be valid message namespaces, TailPaddingNamespaceID or ParitySharesNamespaceID

https://github.com/celestiaorg/celestia-app/blob/main/pkg/appconsts/appconsts.go#L90-L96

Copy link
Member

Choose a reason for hiding this comment

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

Sorry yes, I meant tail padding or parity. Is that alright?

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch! 6f50ff6

return nil, err
}

return node.Tx(context.Background(), hash, false)
Copy link
Member

Choose a reason for hiding this comment

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

[Question][Non Blocking]
Why using the background context when we have the clientCtx?

Copy link
Member Author

Choose a reason for hiding this comment

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

the clientCtx doesn't actually have a context.Context in it, and I didn't want to force the testnode package as a dependency. This is good point tho

rootulp
rootulp previously approved these changes Oct 1, 2022
Comment on lines 32 to 33
// note: the passed application config is currently unused atm, but we plan to
// add support.
Copy link
Collaborator

Choose a reason for hiding this comment

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

[question] which parameter corresponds to the application config?

If present, proposal to explicitly include the parameter name in the note (because I don't think it's tmCfg).
If no longer present, proposal to remove this note.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch 14aca81

testutil/testnode/rpc_client.go Outdated Show resolved Hide resolved
func RandomValidNamespace() namespace.ID {
for {
s := tmrand.Bytes(8)
if bytes.Compare(s, appconsts.MaxReservedNamespace) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

MaxReservedNamespace is greater than the namespace used for transactions, intermediate state roots, or evidence so this conditional will evaluate to false if s matches any of those namespaces.

In other words, the returned s should only be valid message namespaces, TailPaddingNamespaceID or ParitySharesNamespaceID

https://github.com/celestiaorg/celestia-app/blob/main/pkg/appconsts/appconsts.go#L90-L96

Co-authored-by: Rootul P <rootulp@gmail.com>
@evan-forbes
Copy link
Member Author

had to skip the network test while the race detector is on, exactly like what we do for the other larger network test. a376539

@evan-forbes evan-forbes changed the title feat!: Implement an in-process test core node with celestia-app and custom state feat: Implement an in-process test core node with celestia-app and custom state Oct 3, 2022
@evan-forbes evan-forbes enabled auto-merge (squash) October 3, 2022 20:42
Comment on lines 17 to 24
ns := tmrand.Bytes(8)
isReservedNS := bytes.Compare(ns, appconsts.MaxReservedNamespace) <= 0
isParityNS := bytes.Equal(ns, appconsts.ParitySharesNamespaceID)
isTailPaddingNS := bytes.Equal(ns, appconsts.TailPaddingNamespaceID)
if isReservedNS || isParityNS || isTailPaddingNS {
continue
}
return ns
Copy link
Collaborator

Choose a reason for hiding this comment

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

[question] Nice! There are multiple implementations of this function that may benefit from similar parity / tail padding namespace checks:

  1. https://github.com/rootulp/celestia-app/blob/2f26c385831048808d99f4626aa3569df18c187c/app/test_util.go#L178-L185
  2. https://github.com/rootulp/celestia-app/blob/2f26c385831048808d99f4626aa3569df18c187c/testutil/payment/testutil.go#L134-L141
  3. https://github.com/rootulp/celestia-app/blob/2f26c385831048808d99f4626aa3569df18c187c/app/test/block_size_test.go#L299-L306
  4. https://github.com/rootulp/celestia-app/blob/2f26c385831048808d99f4626aa3569df18c187c/pkg/prove/proof_test.go#L249-L257

It's not clear to me if these should be refactored into one function definition. Were they intentionally duplicated to avoid cyclic imports / importing across package boundaries?

@evan-forbes evan-forbes merged commit 07b5bb4 into main Oct 3, 2022
@evan-forbes evan-forbes deleted the evan/test-node branch October 3, 2022 21:20
rach-id pushed a commit to rach-id/celestia-app that referenced this pull request Nov 16, 2022
…stom state (celestiaorg#824)

This PR is based of the
[network](https://github.com/cosmos/cosmos-sdk/tree/main/testutil/network)
tests in the cosmos-sdk. Those tests are focused on running multiple
nodes, while this test only runs a single node validator. This node also
has the full access to change the consensus parameters and the full
tendermint config. This is needed to to have block times shorter than 1
second. There is also discussion to modify the sdk code to only be a
mock, where we need to run a full in process node to include any changes
to tendermint and to not have to apply those same changes to the new
upcoming mock node in the sdk.

While this does have extra features and a built in API, it does have a
lot of duplicate features to our own wrapper around the linked above
network tests. Eventually we should replace the usage of that code in
the integrations tests with this code.

closes celestiaorg#770

Co-authored-by: Rootul P <rootulp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing items that are strictly related to adding or extending test coverage
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Export a public testutil function for use in celestia-node swamp tests
4 participants