Skip to content

lite: Add synchronization in lite verify#2396

Merged
ebuchman merged 4 commits intotendermint:developfrom
HaoyangLiu:bianjie/improve-lite
Sep 28, 2018
Merged

lite: Add synchronization in lite verify#2396
ebuchman merged 4 commits intotendermint:developfrom
HaoyangLiu:bianjie/improve-lite

Conversation

@HaoyangLiu
Copy link
Contributor

Implement the idea in #2386

  • Add synchronization in lite verify
  • Change Certify to Verify

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

One question but code changes look OK to me otherwise. Can we add a few testcases to ensure that this works correctly?

//Get the exact trusted commit for h, and if it is
// equal to shdr, then don't even verify it,
// and just return nil.
trustedFCSameHeight, err := ic.trusted.LatestFullCommit(ic.chainID, shdr.Height, shdr.Height)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this stored in RAM or on disk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both of them will store the commits. Here we create disk db and memory db to cache the verified commits:

memProvider := lite.NewDBProvider("trusted.mem", dbm.NewMemDB()).SetLimit(10)

Actually, I have changed the test to cover the new code. Next I will create a new test to simulate concurrent requests.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

On-disk we can store all, in-memory should be an LRU cache with a configurable size.

@jaekwon
Copy link
Contributor

jaekwon commented Sep 18, 2018

Very cool. Has this been tested HaoyangLiu? What are the next steps?

@HaoyangLiu
Copy link
Contributor Author

@jaekwon
Sorry for delayed replay. Recently I was so busy with IRISNET develop. I have add a small test the cover the new code. Next I will add more test and implement an LRU cache to improve performance.

@xla xla added the C:light Component: Light label Sep 21, 2018
@xla xla changed the title WIP: Add synchronization in lite verify [WIP] Add synchronization in lite verify Sep 21, 2018
@HaoyangLiu
Copy link
Contributor Author

@cwgoes
Currently, two trust store will be created for tendermint lite: memory cache store and db store. The memory cache maximum size is 10. Mayge we should parameterize the size. The trust memory cache will only keep 10 of the highest trust commit, please refer to the cache deleting algorithm. Strictly speaking, though it is not the LRU cache algorithm, I think it is also reasonable and in many cases it is equivalent to LRU algorithm. For instances, in most user cases, user will query the latest blockchain state, such as account information. Then latest trust commits will be cached by memory cache store. The LRU cache algorithm will do the same operation.
In summary, I think the current memory cache store can meet our requirements. But there is an improvement point: parameterizing the memory cache size.
How do you think about this? @cwgoes

@HaoyangLiu
Copy link
Contributor Author

@cwgoes @jaekwon
I have add a test named TestConcurrencyInquirerVerify to verify this changes.

@HaoyangLiu HaoyangLiu changed the title [WIP] Add synchronization in lite verify [R4R] Add synchronization in lite verify Sep 23, 2018
@codecov-io
Copy link

codecov-io commented Sep 23, 2018

Codecov Report

Merging #2396 into develop will decrease coverage by 0.49%.
The diff coverage is 85.71%.

@@            Coverage Diff             @@
##           develop    #2396     +/-   ##
==========================================
- Coverage    61.75%   61.25%   -0.5%     
==========================================
  Files          198      197      -1     
  Lines        16358    16337     -21     
==========================================
- Hits         10102    10008     -94     
- Misses        5434     5463     +29     
- Partials       822      866     +44
Impacted Files Coverage Δ
cmd/tendermint/commands/lite.go 15.38% <50%> (+2.22%) ⬆️
lite/base_verifier.go 76% <75%> (ø) ⬆️
lite/dynamic_verifier.go 62.18% <89.65%> (+5.93%) ⬆️
libs/common/int.go 17.85% <0%> (-82.15%) ⬇️
libs/common/string.go 61.53% <0%> (-15.13%) ⬇️
state/store.go 64.96% <0%> (-5.11%) ⬇️
p2p/node_info.go 45.61% <0%> (-5.04%) ⬇️
libs/autofile/autofile.go 69.69% <0%> (-4.96%) ⬇️
state/services.go 38.46% <0%> (-4.4%) ⬇️
p2p/test_util.go 56.47% <0%> (-4.14%) ⬇️
... and 44 more

@xla xla requested review from jaekwon and removed request for ebuchman, melekes and xla September 26, 2018 11:47
@xla xla added this to the launch milestone Sep 26, 2018
@xla xla changed the title [R4R] Add synchronization in lite verify lite: Add synchronization in lite verify Sep 26, 2018
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

LGTM - needs a review from @jaekwon

@cwgoes
Copy link
Contributor

cwgoes commented Sep 26, 2018

Currently, two trust store will be created for tendermint lite: memory cache store and db store. The memory cache maximum size is 10. Mayge we should parameterize the size.

This sounds OK, parameterize cache size is definitely a good idea. Probably enough for now.

Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

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

👍 :octocat: :shipit: 🍡

Some minor formatting changes, otherwise LGTM.

lerr "github.com/tendermint/tendermint/lite/errors"
"github.com/tendermint/tendermint/types"
"sync"
"fmt"
Copy link
Contributor

Choose a reason for hiding this comment

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

Import order is incorrect it should be:

import (
	// stdlib packages

	// third-party packages
	
	// repo package
)	


dbm "github.com/tendermint/tendermint/libs/db"
log "github.com/tendermint/tendermint/libs/log"
"sync"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

)

func NewVerifier(chainID, rootDir string, client lclient.SignStatusClient, logger log.Logger) (*lite.DynamicVerifier, error) {
func NewVerifier(chainID, rootDir string, client lclient.SignStatusClient, logger log.Logger, cacheSize int) (*lite.DynamicVerifier, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This signature is getting quite large, would benefit from functional options, an example from another part of the codebase:

// SocketPVOption sets an optional parameter on the SocketPV.
type SocketPVOption func(*SocketPV)
// SocketPVAcceptDeadline sets the deadline for the SocketPV listener.
// A zero time value disables the deadline.
func SocketPVAcceptDeadline(deadline time.Duration) SocketPVOption {
return func(sc *SocketPV) { sc.acceptDeadline = deadline }
}
// SocketPVConnDeadline sets the read and write deadline for connections
// from external signing processes.
func SocketPVConnDeadline(deadline time.Duration) SocketPVOption {
return func(sc *SocketPV) { sc.connDeadline = deadline }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xla
I think function options may be not suitable for NewVerifier. Because NewVerifier use these parameters for processing network operation, not just variable assignment.

@HaoyangLiu
Copy link
Contributor Author

@xla
Thanks for your feedback. I will modify the code as your suggestions.

source Provider

// pending map for synchronize concurrent verification requests
pendingVerifications map[int64]chan struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Convention we use is to put the mtx directly above the things it protects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:light Component: Light

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants