private bool OnNewStateRoot(StateRoot state_root) { if (state_root?.Witness is null) { return(false); } if (ValidatedRootIndex != null && state_root.Index <= ValidatedRootIndex) { return(false); } if (LocalRootIndex is null) { throw new InvalidOperationException(nameof(StateStore) + " could not get local root index"); } if (LocalRootIndex < state_root.Index && state_root.Index < LocalRootIndex + MaxCacheCount) { cache.Add(state_root.Index, state_root); return(true); } using var state_snapshot = Singleton.GetSnapshot(); StateRoot local_root = state_snapshot.GetStateRoot(state_root.Index); if (local_root is null || local_root.Witness != null) { return(false); } if (!state_root.Verify(StatePlugin.System.Settings, StatePlugin.System.StoreView)) { return(false); } if (local_root.RootHash != state_root.RootHash) { return(false); } state_snapshot.AddValidatedStateRoot(state_root); state_snapshot.Commit(); UpdateCurrentSnapshot(); system.Verifier?.Tell(new VerificationService.ValidatedRootPersisted { Index = state_root.Index }); return(true); }
private bool OnNewStateRoot(StateRoot state_root) { if (state_root?.Witness is null) { return(false); } if (state_root.Index <= ValidatedRootIndex) { return(false); } if (LocalRootIndex < state_root.Index && state_root.Index < LocalRootIndex + MaxCacheCount) { cache.Add(state_root.Index, state_root); return(true); } using var state_snapshot = Singleton.GetSnapshot(); StateRoot local_root = state_snapshot.GetStateRoot(state_root.Index); if (local_root is null || local_root.Witness != null) { return(false); } using var snapshot = Blockchain.Singleton.GetSnapshot(); if (!state_root.Verify(snapshot)) { return(false); } if (local_root.RootHash != state_root.RootHash) { return(false); } state_snapshot.AddValidatedStateRoot(state_root); state_snapshot.Commit(); UpdateCurrentSnapshot(); //Tell validation service return(true); }