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

block validation by rootchain contract #37

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Conversation

dCanyon
Copy link
Contributor

@dCanyon dCanyon commented Jan 24, 2019

No description provided.

@@ -34,7 +34,7 @@ import (
)

var (
EmptyRootHash = DeriveSha(Transactions{})
EmptyRootHash = DeriveShaFromBMT(Transactions{})
Copy link
Contributor

@4000D 4000D Jan 24, 2019

Choose a reason for hiding this comment

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

EmptyRootHash stands for empty patricia tree, and it is used in ethclient and storage hash. So it should not be touched.

We use additional empty root, EmptyBMTRootHash, for empty binary merkle tree.

rootchainAddress, rootchainContract, err := deployRootChain(genesis)

chainConfig.RootchainAddress = rootchainAddress
chainConfig.RootchainURL = "ws://localhost:8546"
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. do not hardcode url.

pls/backend.go Outdated
@@ -159,6 +159,10 @@ func New(ctx *node.ServiceContext, config *Config) (*Plasma, error) {
}
cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieCleanLimit: config.TrieCleanCache, TrieDirtyLimit: config.TrieDirtyCache, TrieTimeLimit: config.TrieTimeout}
)

pls.chainConfig.RootchainAddress = config.RootChainContract
pls.chainConfig.RootchainURL = config.RootChainURL
Copy link
Contributor

Choose a reason for hiding this comment

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

chainConfig.RootchainAddress and chainConfig.RootchainURL is duplicated with pls.Config.

rootchainAddress, rootchainContract, err := deployRootChain(genesis)

chainConfig.RootchainAddress = rootchainAddress
chainConfig.RootchainURL = "ws://localhost:8546"
Copy link
Contributor

Choose a reason for hiding this comment

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

do not use literal

// Validate 3 roots from block committed on root chain against the received roots
// and throw an error if they don't match
validate := func() error {
tblock, err := v.rootchain.GetBlock(baseCallOpt, block.Difficulty(), block.Number())
Copy link
Contributor

Choose a reason for hiding this comment

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

In case of v.rootchain == nil, skip the validation. It is useful when blockchain without RootChain contract is required.

log.Error("failed to make rootchainContract", "err", err)
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If rootchain is needed only for validator, just add it as argument of newBlockValidator (as well as NewBlockChain).

It makes us keep params.ChainConfig untouched.

return nil
}

timer := time.NewTimer(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

we may use time.Ticker rather than time.Timer.

for {
select {
case <-timer.C:
if v.bc.LastSubmittedNumber.Cmp(block.Number()) < 0 && v.bc.LastSubmittedFork.Cmp(block.Difficulty()) < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

LastSubmittedNumber and LastSubmittedFork may be nil if block is not submitted. Read it from RootChain contract and save it when pls is created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think LastSubmittedNumber and LastSubmittedFork are not necessary since we can check whether a specific block is submitted or not by checking the return value of rootchain.Getblock() is empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, Every validate requires one JSONRPC communication.
I think we can also use LastSubmittedNumber and LastSubmittedFork when we submit TX (in the part of gas adjustment)

miner/worker.go Outdated
@@ -1091,9 +1091,6 @@ func (w *worker) commitNewWorkForORB(interrupt *int32, noempty bool, timestamp i
log.Error("Failed to prepare header for mining", "err", err)
return
}
if w.env.IsUserActivated && w.env.NumURBmined.Cmp(big.NewInt(0)) == 0 {
header.Difficulty.Add(header.Difficulty, big.NewInt(1))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Where the first URB with difficulty + 1 is created?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It caused build error since this version do not support UAF. So I deleted it for testing my code. It will added if you merge #31. So don't worry about this. Additionally, there is no more w.env.NumURBmined field in new version.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you merge and resolve the conflict in current develop branch? This PR is based on older commit, so incurs this kind of issue. If you merge newer one, it will help me to review.

@@ -108,10 +108,10 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
if head.UncleHash != types.EmptyUncleHash && len(body.UncleHashes) == 0 {
return nil, fmt.Errorf("server returned empty uncle list but block header indicates uncles")
}
if head.TxHash == types.EmptyRootHash && len(body.Transactions) > 0 {
if head.TxHash == types.EmptyBMTRootHash && len(body.Transactions) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

ethclient is ethereum JSONRPC client and it is used when to connect to root chain. On the other hand, plsclient is used to connect plasma JSONRPC server.

It have to use EmptyRootHash instead of EmptyBMTRootHash because ethereum client use merkle patricia trie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants