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

Implement child chain and client #26

Merged
merged 14 commits into from Feb 28, 2018

Conversation

DavidKnott
Copy link
Contributor

@DavidKnott DavidKnott commented Feb 14, 2018

Implements the Plasma child chain and a cli to interface with both the plasma child chain and the root chain.
The next PRs will add more tests, contain validations for child chain transactions, and will further improve the README.
@paulperegud @robinclart

Makefile Outdated
.PHONY: help
help:
@echo "root-chain" - starts the root chain and
@echo "root-chain" - starts the root chain
@echo "child-chin" - starts the child chain
Copy link

Choose a reason for hiding this comment

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

spelling of "child-chin"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dao fixed it, thanks!

@DavidKnott
Copy link
Contributor Author

@jdkanani Glad you're working on Plasma MVP! Given that this OMG's plasma repo it'd be great if the focus stayed on reviewing this PR.

@jdkanani
Copy link

@DavidKnott Thank you. Sorry about that. Removed my comment :)

@smartcontracts smartcontracts mentioned this pull request Feb 16, 2018
Copy link
Contributor

@smartcontracts smartcontracts left a comment

Choose a reason for hiding this comment

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

Solid from a high-level. A few nitpicks and minor changes to make sure tests still pass.

spent = self.blocks[blknum].transaction_set[txindex].spent2
amount = self.blocks[blknum].transaction_set[txindex].amount2
assert spent is False
spent = True
Copy link
Contributor

Choose a reason for hiding this comment

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

spent = True doesn't seem to have a purpose

self.current_block = Block()

def get_transaction(self, blknum, txindex):
return rlp.encode(self.block[blknum].transaction_set[txindex]).hex()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be self.blocks[...]

@@ -2,22 +2,34 @@

We're implementing the [Minimum Viable Plasma](https://ethresear.ch/t/minimal-viable-plasma/426)

Current repo includes:
Install dependencies with:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this generally needs to be cleaned up but that's for another PR.

from plasma.child_chain.transaction import Transaction


@main.command('start')
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly not a great UX. omg start <command> is more annoying to use than omg <command>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kfichter The user only has to enter omg start once which enters them into the cli and from there they just enter <command>.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah okay, understood.

self.client = Client()
self.db = plyvel.DB('/tmp/plasma_mvp_db/', create_if_missing=True)
self.current_block = self.client.get_current_block_num()
self.synced_block = 1
Copy link
Contributor

Choose a reason for hiding this comment

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

synced_block and client_cmds could be converted to class attributes.

)


@click.group(invoke_without_command=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be @click.group(invoke_without_command=True, context_settings=CONTEXT_SETTINGS) for this to work.

"jsonrpc": "2.0",
"id": 0,
}
response = requests.post(self.url, data=json.dumps(payload),
Copy link
Contributor

Choose a reason for hiding this comment

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

Easier to use requests.post(self.url, json=payload).json(). This also removes the need for the additional Content-Type header.

def __init__(self, root_chain_provider=HTTPProvider('http://localhost:8545'), child_chain_url="http://localhost:8546/jsonrpc"):
deployer = Deployer(root_chain_provider)
abi = json.load(open("contract_data/RootChain.json"))
self.w3 = deployer.w3
Copy link
Contributor

Choose a reason for hiding this comment

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

Client.w3 is never used after this, could just replace with self.root_chain = deployer.w3.eth...


def create_contract(self, path, args=(), gas=4410000, sender=t.k0):
abi, bytecode = self.compile_contract(path, args)
abi, bytecode, contract_name = self.compile_contract(path, args)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change needs to be implemented here:
https://github.com/omisego/plasma-mvp/blob/30b7cfbd9e713f3093cda1cb2660f518fe523f0c/tests/conftest.py#L60

Can be implemented as

abi, bytecode, _ = Deployer().compile_contract(path, args)

as we don't need the contract name in order to complete that test.

make test fails otherwise.

'ethereum==2.1.3',
'web3',
'ethereum==2.3.0',
'web3==3.16.4',
Copy link
Contributor

Choose a reason for hiding this comment

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

Closes #18, conveniently

@DavidKnott
Copy link
Contributor Author

@kfichter I made some of the changes you suggested.

Copy link
Contributor

@smartcontracts smartcontracts left a comment

Choose a reason for hiding this comment

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

Caught some small errors in the new changes, should be fine once these are fixed.

self.synced_block = 1
self.client_cmds = dict(
synced_block = 1
client_cmds = dict(
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving client_cmds to a class variable means we don't have access to self so we need to change to:

    client_cmds = dict(
        sync=ClientParser.sync_child_chain,
        deposit=ClientParser.deposit,
        send_tx=ClientParser.send_tx,
        submit_block=ClientParser.submit_block,
        withdraw=ClientParser.withdraw,
        help=ClientParser.help,
    )

def process_input(self, inp):
self.inp = inp
command = self.inp[0]
if command not in self.client_cmds:
if command not in client_cmds:
Copy link
Contributor

Choose a reason for hiding this comment

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

We still need the self reference unless we make client_cmds a global here.

@@ -22,8 +22,7 @@ def send_request(self, method, args):
"jsonrpc": "2.0",
"id": 0,
}
response = requests.post(self.url, data=json.dumps(payload),
headers=headers).json()
response = requests.post(self.url, data=payload).json()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be json=payload if we want to send as JSON w/o headers = {'content-type': 'application/json'}. Might as well remove headers = {'content-type': 'application/json'} if we're going this route.

@DavidKnott DavidKnott merged commit 0b478ec into omgnetwork:master Feb 28, 2018
deckmon added a commit to deckmon/plasma-mvp that referenced this pull request Jun 23, 2018
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.

None yet

4 participants