Implementation of the Light Client Verification Protocol.
Tested with Rust 1.44+, may work on older versions.
See documentation on crates.io.
The code below demonstrates the main use case for the Tendermint Light Client: syncing to the latest block, verifying it, and performing fork detection.
Please refer to the light_client
example for fully working code.
```rust let primaryinstance: Instance = makeinstance(primary, primaryaddr, primarypath); let witnessinstance: Instance = makeinstance(witness, witnessaddr, witnesspath);
let mut peeraddr = HashMap::new(); peeraddr.insert(primary, primaryaddr); peeraddr.insert(witness, witness_addr);
let peerlist = PeerList::builder() .primary(primary, primaryinstance) .witness(witness, witness_instance) .build();
let mut supervisor = Supervisor::new( peerlist, ProdForkDetector::default(), ProdEvidenceReporter::new(peeraddr), );
let mut handle = supervisor.handle();
// Spawn the supervisor in its own thread. std::thread::spawn(|| supervisor.run());
loop { // Synchronously query the supervisor via a handle let block = handle.verifytohighest();
match block {
Ok(light_block) => {
println!("[info] synced to block {}", light_block.height());
}
Err(e) => {
println!("[error] sync failed: {}", e);
}
});
std::thread::sleep(Duration::from_millis(800));
} ```
Copyright © 2020 Informal Systems
Licensed under the Apache License, Version 2.0 (the "License"); you may not use the files in this repository except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.