MCPcopy Create free account
hub / github.com/33cn/chain33 / procExecAddBlock

Method procExecAddBlock

executor/executor.go:380–480  ·  view source on GitHub ↗
(msg *queue.Message)

Source from the content-addressed store, hash-verified

378}
379
380func (exec *Executor) procExecAddBlock(msg *queue.Message) {
381
382 //panic 处理
383 defer func() {
384 if r := recover(); r != nil {
385 elog.Error("add blk panic error", "err", r)
386 msg.Reply(exec.client.NewMessage("", types.EventReceipts, types.ErrExecPanic))
387 return
388 }
389 }()
390 datas := msg.GetData().(*types.BlockDetail)
391 b := datas.Block
392 ctx := &executorCtx{
393 stateHash: b.StateHash,
394 height: b.Height,
395 blocktime: b.BlockTime,
396 difficulty: uint64(b.Difficulty),
397 mainHash: b.MainHash,
398 mainHeight: b.MainHeight,
399 parentHash: b.ParentHash,
400 }
401 var localdb dbm.KVDB
402 if !exec.disableLocal {
403 localdb = NewLocalDB(exec.client, exec.qclient, false)
404 defer localdb.(*LocalDB).Close()
405 }
406 execute := newExecutor(ctx, exec, localdb, b.Txs, datas.Receipts)
407 //因为mvcc 还没有写入,所以目前的mvcc版本是前一个区块的版本
408 execute.enableMVCC(datas.PrevStatusHash)
409 var kvset types.LocalDBSet
410 for _, kv := range datas.KV {
411 err := execute.stateDB.Set(kv.Key, kv.Value)
412 if err != nil {
413 panic(err)
414 }
415 }
416 for name, plugin := range globalPlugins {
417 kvs, ok, err := plugin.CheckEnable(execute, exec.pluginEnable[name])
418 if err != nil {
419 panic(err)
420 }
421 if !ok {
422 continue
423 }
424 if len(kvs) > 0 {
425 kvset.KV = append(kvset.KV, kvs...)
426 }
427
428 kvs, err = plugin.ExecLocal(execute, datas)
429 if err != nil {
430 msg.Reply(exec.client.NewMessage("", types.EventAddBlock, err))
431 return
432 }
433 if len(kvs) > 0 {
434 kvset.KV = append(kvset.KV, kvs...)
435 for _, kv := range kvs {
436 err := execute.localDB.Set(kv.Key, kv.Value)
437 if err != nil {

Callers 1

SetQueueClientMethod · 0.95

Calls 15

newExecutorFunction · 0.85
checkProxyExecTxMethod · 0.80
proxyExecTxMethod · 0.80
FromMethod · 0.80
execLocalTxMethod · 0.80
NewLocalDBFunction · 0.70
ErrorMethod · 0.65
ReplyMethod · 0.65
NewMessageMethod · 0.65
GetDataMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected