Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PIE-1810] Update export subcommand to export blocks in rlp format #1852

Merged
merged 7 commits into from
Aug 14, 2019

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Aug 14, 2019

PR description

Update blocks export subcommand to export blocks in rlp format. Rearrange import / export utilities so that these classes are grouped together with consistent naming.

Copy link
Contributor

@AbdelStark AbdelStark left a comment

Choose a reason for hiding this comment

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

Left few comments. Looks good to me.

protected void exportBlock(final FileOutputStream outputStream, final Block block)
throws IOException {
final BytesValue rlp = RLP.encode(block::writeTo);
outputStream.write(rlp.getArrayUnsafe());
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Are you writing binary data in the file ? Is it what we want ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this matches the format the blocks import accepts

// throws Exception {
//
// final long startBlock = 0L;
// final long endBlock = 1L;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are those tests commented ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

old commit

final long endBlock = maybeEndBlock.orElse(blockchain.getChainHeadBlockNumber() + 1L);
checkArgument(startBlock >= 0 && endBlock >= 0, "Start and end blocks must be greater than 0.");
checkArgument(startBlock < endBlock, "Start block must be less than end block");

Copy link
Contributor

Choose a reason for hiding this comment

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

[optional] maybe a check arg that startblock <= chainHead?

@Option(
names = "--to",
required = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't currently support export to standard output correct? An absent --to option is how I wold expect that to be configured. It may be interesting for json export but it sounds wrong for RLP export.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, no one wants to read binary data from std out :D But yeah, we might need to rethink it for json export. Although given you can potentially export massive amounts of data, doesn't seem like the worst thing to require a file to export to.

exportRlpFormat(controller);
break;
default:
throw new ParameterException(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, this future proofs us against random formats being added to the enum and by effect being exposed to the CLI.

+ ") must be greater start block ("
+ startBlock
+ ").");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't know the state of the blockchain here correct? So we can't assert startblock is in the chain? I think this could be a user error we can detect (somehow) and we should provide the user feedback on. Perhaps we could count the number of blocks exported and return it as part of the exportBlocks method, and log a warning or output the console if no blocks were exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll currently log a warning if any blocks in the defined range were missing. Might be a good idea to error out if no blocks are exported though ... I may follow-up on that in another PR.

File databaseDirectory = new File(databasePath.toString());
if (!databaseDirectory.exists()
|| !databaseDirectory.isDirectory()
|| databaseDirectory.list().length == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isDirectory implies exists so exists can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is more readable but just for fun, the whole thing can be determined from list() because it returns null if it's not a directory or doesn't exist :P
Optional.ofNullable(databaseDirectory.list()).filter(files -> files.length == 0).isPresent()

@mbaxter mbaxter merged commit a7d07e2 into PegaSysEng:master Aug 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants