Skip to content

Update verifier to prevent duplicate requests and cache verified headers #2386

@cwgoes

Description

@cwgoes

From in-person discussion, changes to https://github.com/tendermint/tendermint/blob/master/lite/dynamic_verifier.go#L59

// If the validators have changed since the last known time, it looks to
// ic.trusted and ic.source to prove the new validators.  On success, it will
// try to store the SignedHeader in ic.trusted if the next
// validator can be sourced.
func (ic *DynamicVerifier) Certify(shdr types.SignedHeader) error {

    // TODO: If I'm already trying to certify this,
    // then block on the old request,
    // and then resume once the old request is done.

    // TODO: move the below to "WaitForPendingVerifications(height)" and call it.
    // ic.mtx.Lock()
    // if pending := ic.pendingVerifications[shdr.height]; pending != nil
    //   ic.mtx.Unlock()
    //   <- pending // pending is chan struct{}
    // else
    //   pending := make(chan struct{}, 0)
    //   ic.pendingVerifications[shdr.height] = pending
    //   defer func() {
    //     close(pending)
    //     ic.mtx.Lock()
    //     delete ic.pendingVerifications[shrd.height]
    //     ic.mtx.Unlock()
    //   }()
    //   ic.mtx.Unlock()

    // TODO: Get the exact trusted commit for h, and if it is
    // equal to shdr, then don't even verify it,
    // and just return nil.

    // Get the latest known full commit <= h-1 from our trusted providers.
    // The full commit at h-1 contains the valset to sign for h.
    h := shdr.Height - 1
    trustedFC, err := ic.trusted.LatestFullCommit(ic.chainID, 1, h)

This issue covers:

  • Adding the height-based lock-release code as above so that we avoid performing duplicate computation for the same height
  • Caching trusted commits that we've already fetched & verifie
  • Renaming all instances of Certify to Verify

cc @HaoyangLiu @jaekwon

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions