MCPcopy Create free account
hub / github.com/CPChain/chain / BlockChain

Struct BlockChain

core/blockchain.go:145–208  ·  view source on GitHub ↗

BlockChain represents the canonical chain given a database with a genesis block. The Blockchain manages chain imports, reverts, chain reorganisations. Importing blocks in to the block chain happens according to the set of rules defined by the two stage Validator. Processing of blocks is done using

Source from the content-addressed store, hash-verified

143// included in the canonical one where as GetBlockByNumber always represents the
144// canonical chain.
145type BlockChain struct {
146 chainConfig *configs.ChainConfig // Chain & network configuration
147 cacheConfig *CacheConfig // Cache configuration for pruning
148
149 db database.Database // Low level persistent database to store final content in
150 triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
151 gcproc time.Duration // Accumulates canonical block processing for trie dumping
152
153 hc *HeaderChain
154 rmLogsFeed event.Feed
155 chainFeed event.Feed
156 chainSideFeed event.Feed
157 chainHeadFeed event.Feed
158 chainLatestFeed event.Feed
159 logsFeed event.Feed
160 scope event.SubscriptionScope
161 genesisBlock *types.Block
162
163 mu sync.RWMutex // global mutex for locking chain operations
164 chainmu sync.RWMutex // blockchain insertion lock
165 procmu sync.RWMutex // block processor lock
166
167 checkpoint int // checkpoint counts towards the new checkpoint
168 currentBlock atomic.Value // Current head of the block chain
169 currentFastBlock atomic.Value // Current head of the fast-sync chain (may be above the block chain!)
170
171 stateCache state.Database // State database to reuse between imports (contains state cache)
172 bodyCache *lru.Cache // Cache for the most recent block bodies
173 bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format
174 blockCache *lru.Cache // Cache for the most recent entire blocks
175 futureBlocks *lru.Cache // future blocks are blocks added for later processing
176 unknownAncestors *lru.Cache // unknown ancestor blocks are blocks added for later processing
177
178 Quit chan struct{} // blockchain quit channel
179 running int32 // running must be called atomically
180 // procInterrupt must be atomically called
181 procInterrupt int32 // interrupt signaler for block processing
182 wg sync.WaitGroup // chain processing wait group for shutting down
183
184 engine consensus.Engine
185 processor Processor // block processor interface
186 validator Validator // block and state validator interface
187 vmConfig vm.Config
188
189 badBlocks *lru.Cache // Bad block cache
190 // pendingBlocks *lru.Cache // not enough signatures block cache
191
192 privateStateCache state.Database // State database to reuse between imports (contains state cache)
193 remoteDB database.RemoteDatabase // Remote database for huge amount data storage
194
195 insertChainProtectLock sync.RWMutex
196
197 knownHeadNumber uint64 // number of known head of current chain
198 knownHeadHash common.Hash // hash of known head of current chain
199 knownHeadLock sync.RWMutex
200
201 mux *event.TypeMux
202 srCache *statesAndReceiptsCache // state and receipt cache

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected