Esempio n. 1
0
        public void UpdateLocalStateRoot(uint height, List <DataCache.Trackable> change_set)
        {
            using StateSnapshot state_snapshot = Singleton.GetSnapshot();
            foreach (var item in change_set)
            {
                switch (item.State)
                {
                case TrackState.Added:
                    state_snapshot.Trie.Put(item.Key, item.Item);
                    break;

                case TrackState.Changed:
                    state_snapshot.Trie.Put(item.Key, item.Item);
                    break;

                case TrackState.Deleted:
                    state_snapshot.Trie.Delete(item.Key);
                    break;
                }
            }
            UInt256   root_hash  = state_snapshot.Trie.Root.Hash;
            StateRoot state_root = new StateRoot
            {
                Version  = StateRoot.CurrentVersion,
                Index    = height,
                RootHash = root_hash,
                Witness  = null,
            };

            state_snapshot.AddLocalStateRoot(state_root);
            state_snapshot.Commit();
            UpdateCurrentSnapshot();
            system.Verifier?.Tell(new VerificationService.BlockPersisted {
                Index = height
            });
            CheckValidatedStateRoot(height);
        }