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

Effects of a nil Sha256Checksum in a ChecksummedGenesisDoc #2938

Closed
andynog opened this issue Apr 29, 2024 · 2 comments · Fixed by #3526
Closed

Effects of a nil Sha256Checksum in a ChecksummedGenesisDoc #2938

andynog opened this issue Apr 29, 2024 · 2 comments · Fixed by #3526
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation P:integrator-experience Priority: Improve experience for integrators

Comments

@andynog
Copy link
Contributor

andynog commented Apr 29, 2024

The GenesisDocProvider is a type alias for a func

type GenesisDocProvider func() (ChecksummedGenesisDoc, error)

When the logic was implemented, I believe that the expectation was that this GenesisDocProvider was going to be 'provided' using DefaultGenesisDocProviderFunc, which calculates the sha256 checksum from the jsonBlob of the genesis file content

func DefaultGenesisDocProviderFunc(config *cfg.Config) GenesisDocProvider {

The problem is that this provider could come from a custom provider. For example, the Cosmos-SDK has a different genesis signature and it needs to pass it's own provider logic, something like:

	appGenesisProvider := func() (node.ChecksummedGenesisDoc, error) {
		appGenesis, err := genutiltypes.AppGenesisFromFile(cmtCfg.GenesisFile())
		if err != nil {
			return node.ChecksummedGenesisDoc{}, err
		}
		gen, err := appGenesis.ToGenesisDoc()
		if err != nil {
			return node.ChecksummedGenesisDoc{}, err
		}
		return node.ChecksummedGenesisDoc{GenesisDoc: gen}, nil
	}

which returns a func() (ChecksummedGenesisDoc, error) that can be used in a node.NewNode() as the GenesisDocProvider, e.g.

tmNode, err := node.NewNode(
		context.TODO(),
		...
		appGenesisProvider,
		...
	)

but this might cause issues in

func LoadStateFromDBOrGenesisDocProviderWithConfig(

because the Sha256Checksum field is not validated (look at the example above (return node.ChecksummedGenesisDoc{GenesisDoc: gen}) so it will be nil.

It will fail when trying to save it in the stateDB here because a nil value cannot be saved on the database

if err = stateDB.SetSync(genesisDocHashKey, csGenDoc.Sha256Checksum); err != nil {

and there is other logic in this function that relies on a Sha256Checksum, so in my opinion, we might need to account for that in the code or at least add more tests. I agree that in part this is caused by a integrator not adding the checksum (maybe we need to add some more information to the docs to say that is expected), but at the same time as a defensive measure we might need to ensure we can handle this scenario and that it will not cause other issues in the future.

@andynog andynog added bug Something isn't working documentation Improvements or additions to documentation P:integrator-experience Priority: Improve experience for integrators labels Apr 29, 2024
@andynog andynog modified the milestone: 2024-Q2 Apr 29, 2024
@andynog andynog changed the title custom GenesisDocProvider might have a nil Sha256Checksum custom GenesisDocProvider might have a ChecksummedGenesisDoc with a nil Sha256Checksum Apr 29, 2024
@andynog andynog changed the title custom GenesisDocProvider might have a ChecksummedGenesisDoc with a nil Sha256Checksum GenesisDocProvider might have a ChecksummedGenesisDoc with a nil Sha256Checksum Apr 29, 2024
@andynog andynog changed the title GenesisDocProvider might have a ChecksummedGenesisDoc with a nil Sha256Checksum custom GenesisDocProvider might return a ChecksummedGenesisDoc with a nil Sha256Checksum Apr 29, 2024
@andynog andynog changed the title custom GenesisDocProvider might return a ChecksummedGenesisDoc with a nil Sha256Checksum Effects of a nil Sha256Checksum in a ChecksummedGenesisDoc Apr 30, 2024
@sergio-mena
Copy link
Contributor

Can you come up with a failing unit test that demonstrates the problem?

@alesforz
Copy link
Contributor

Can you come up with a failing unit test that demonstrates the problem?

Check #3526.

github-merge-queue bot pushed a commit that referenced this issue Jul 24, 2024
…sn't nil. (#3526)

Closes #2938.

### Changes
- Added unit test for the affected function
`LoadStateFromDBOrGenesisDocProviderWithConfig` to showcase the problem

---

#### PR checklist

- [x] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation P:integrator-experience Priority: Improve experience for integrators
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants