Skip to content

Commit

Permalink
Change poet genesis to poet registration create
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Drozd <[email protected]>
  • Loading branch information
nick-drozd committed Nov 14, 2017
1 parent f2c660f commit 4e07397
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 29 deletions.
3 changes: 2 additions & 1 deletion bin/generate_cli_output
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ save_usage settings-tp
save_usage identity-tp

save_usage poet
save_usage poet genesis
save_usage poet enclave
save_usage poet registration
save_usage poet registration create

save_usage intkey
save_usage intkey set
Expand Down
10 changes: 5 additions & 5 deletions consensus/poet/cli/sawtooth_poet_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from colorlog import ColoredFormatter

from sawtooth_poet_cli.exceptions import CliException
from sawtooth_poet_cli.genesis import add_genesis_parser
from sawtooth_poet_cli.genesis import do_genesis
from sawtooth_poet_cli.registration import add_registration_parser
from sawtooth_poet_cli.registration import do_registration
from sawtooth_poet_cli.enclave import add_enclave_parser
from sawtooth_poet_cli.enclave import do_enclave

Expand Down Expand Up @@ -99,7 +99,7 @@ def create_parser(prog_name):
subparsers = parser.add_subparsers(title='subcommand', dest='command')
subparsers.required = True

add_genesis_parser(subparsers, parent_parser)
add_registration_parser(subparsers, parent_parser)
add_enclave_parser(subparsers, parent_parser)

return parser
Expand All @@ -120,8 +120,8 @@ def main(prog_name=os.path.basename(sys.argv[0]), args=None,
verbose_level = args.verbose
setup_loggers(verbose_level=verbose_level)

if args.command == 'genesis':
do_genesis(args)
if args.command == 'registration':
do_registration(args)
elif args.command == 'enclave':
do_enclave(args)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,33 @@
VR_NAMESPACE + sha256('validator_map'.encode()).hexdigest()


def add_genesis_parser(subparsers, parent_parser):
"""Add argument parser arguments for the `poet genesis` subcommand.
def add_registration_parser(subparsers, parent_parser):
"""Add argument parser arguments for the `poet registration`
subcommand
"""
description = 'Creates a Batch for the genesis block'
description = 'Provides subcommands for creating PoET registration'

parser = subparsers.add_parser(
'genesis',
'registration',
help=description,
description=description + '.')

registration_sub = parser.add_subparsers(
title='subcommands', dest='subcommand')
registration_sub.required = True

add_create_parser(registration_sub, parent_parser)


def add_create_parser(subparsers, parent_parser):
"""Add argument parser arguments for the `poet registration create`
subcommand.
"""
description = \
'Creates a batch to enroll a validator in the validator registry'

parser = subparsers.add_parser(
'create',
help=description,
description=description + '.')

Expand Down Expand Up @@ -75,8 +95,15 @@ def add_genesis_parser(subparsers, parent_parser):
help='the most recent block identifier to use as a sign-up nonce')


def do_genesis(args):
"""Executes the `poet genesis` subcommand.
def do_registration(args):
if args.subcommand == 'create':
do_create(args)
else:
raise AssertionError('Invalid command: {}'.format(args.subcommand))


def do_create(args):
"""Executes the `poet registration` subcommand.
This command generates a validator registry transaction and saves it to a
file, whose location is determined by the args. The signup data, generated
Expand Down
11 changes: 6 additions & 5 deletions consensus/poet/cli/tests/test_genesis/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ def setUp(self):
def tearDown(self):
shutil.rmtree(self._temp_dir)

@patch('sawtooth_poet_cli.genesis.PoetKeyStateStore')
@patch('sawtooth_poet_cli.genesis.config.get_data_dir')
@patch('sawtooth_poet_cli.genesis.config.get_key_dir')
@patch('sawtooth_poet_cli.registration.PoetKeyStateStore')
@patch('sawtooth_poet_cli.registration.config.get_data_dir')
@patch('sawtooth_poet_cli.registration.config.get_key_dir')
def test_run_simulator_genesis(self,
get_key_dir_fn,
get_data_dir_fn,
mock_store):
"""Test generating a Validator Registry transaction, which is written
to a file.
This test executes the `poet genesis` command. The expected output is:
This test executes the `poet registration create` command. The
expected output is:
- a BatchList written to a file at <temp_dir>/poet_genesis.batch
- the serialized sealed signup data is written to the key state store
Expand All @@ -62,7 +63,7 @@ def test_run_simulator_genesis(self,
public_key = self._create_key()

main('poet',
args=['genesis',
args=['registration', 'create',
'-o', os.path.join(self._temp_dir, 'poet-genesis.batch')])

self._assert_validator_transaction(public_key, 'poet-genesis.batch')
Expand Down
24 changes: 18 additions & 6 deletions docs/source/cli/poet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,33 @@ Batch for the genesis block. For more information, see
poet
====

The poet command generates information for configuring a node to use
Sawtooth with the PoET consensus method. The genesis subcommand
The ``poet`` command generates information for configuring a node to
use Sawtooth with the PoET consensus method. The genesis subcommand
creates a Batch for the genesis block. The enclave subcommand
generates enclave setup information.

.. literalinclude:: output/poet_usage.out
:language: console
:linenos:

poet genesis
============
poet registration
=================

The ``poet registration`` subcommand provides a command to work with
the PoET validator registry.

.. literalinclude:: output/poet_registration_usage.out
:language: console
:linenos:

poet registration create
========================

The ``poet genesis`` subcommand creates a Batch for the genesis Block.
The ``poet registration create`` subcommand creates a batch to enroll
a validator in the network's validator registry. It must be run from
the validator host wishing to enroll.

.. literalinclude:: output/poet_genesis_usage.out
.. literalinclude:: output/poet_registration_create_usage.out
:language: console
:linenos:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/sysadmin_guide/configure_sgx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Create a poet-genesis batch:

.. code-block:: console
$ poet genesis -k /etc/sawtooth/keys/validator.priv \
$ poet registration create -k /etc/sawtooth/keys/validator.priv \
--enclave-module sgx -o poet_genesis.batch
Writing key state for PoET public key: 0387a451...9932a998
Generating poet_genesis.batch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ services:
sawtooth.poet.valid_enclave_measurements=$$(poet enclave measurement) \
sawtooth.poet.valid_enclave_basenames=$$(poet enclave basename) \
-o config.batch && \
poet genesis -k /etc/sawtooth/keys/validator.priv -o poet.batch && \
poet registration create -k /etc/sawtooth/keys/validator.priv -o poet.batch && \
sawtooth config proposal create \
-k /etc/sawtooth/keys/validator.priv \
$$(/project/sawtooth-core/integration/sawtooth_integration/tests/poet_liveness_data/poet-settings.sh) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
sawtooth.poet.valid_enclave_measurements=$$(poet enclave measurement) \
sawtooth.poet.valid_enclave_basenames=$$(poet enclave basename) \
-o config.batch && \
poet genesis -o poet.batch && \
poet registration create -o poet.batch && \
sawtooth admin genesis \
config-genesis.batch config.batch poet.batch && \
sawtooth-validator -v \
Expand Down
2 changes: 1 addition & 1 deletion integration/sawtooth_integration/tests/node_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def validator_cmds(num,
'-o {}'.format(os.path.join(sawtooth_home, 'data', 'config.batch'))
])

poet = 'poet genesis -k {} -o {}'.format(priv, os.path.join(
poet = 'poet registration create -k {} -o {}'.format(priv, os.path.join(
sawtooth_home, 'data', 'poet.batch'))

genesis = ' '.join([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ def validator_genesis_init(sawtooth_home_genesis,
'-o', os.path.join(sawtooth_home_genesis, 'data', 'config.batch')
], check=True)

subprocess.run(['poet',
'genesis',
subprocess.run(['poet', 'registration', 'create',
'-k', priv,
'-o', os.path.join(
sawtooth_home_genesis, 'data', 'poet.batch')],
Expand Down

0 comments on commit 4e07397

Please sign in to comment.