diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 8043fe2cc..9e0802be5 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -328,6 +328,7 @@ func prepare(ctx *cli.Context) { // It creates a default node based on the command line arguments and runs it in // blocking mode, waiting for it to be shut down. func geth(ctx *cli.Context) error { + //begin PluGeth code injection if err := plugins.Initialize(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "plugins"), ctx); err != nil { return err } @@ -346,7 +347,7 @@ func geth(ctx *cli.Context) error { } defer stack.Close() stack.RegisterAPIs(pluginGetAPIs(stack, wrapperBackend)) - + //end PluGeth code injection startNode(ctx, stack, backend, false) stack.Wait() return nil diff --git a/core/blockchain.go b/core/blockchain.go index ccf8611db..708677b1e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1313,6 +1313,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types externTd := new(big.Int).Add(block.Difficulty(), ptd) if status == CanonStatTy { + //begin PluGeth code injection pluginNewHead(block, block.Hash(), logs, externTd) bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs}) if len(logs) > 0 { @@ -1329,7 +1330,7 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types } else { pluginNewSideBlock(block, block.Hash(), logs) bc.chainSideFeed.Send(ChainSideEvent{Block: block}) - } + } // end PluGeth code injection return status, nil } @@ -2016,7 +2017,9 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { msg = "Large chain reorg detected" logFn = log.Warn } + //begin PluGeth code injection pluginReorg(commonBlock, oldChain, newChain) + //begin Plugeth code injection logFn(msg, "number", commonBlock.Number(), "hash", commonBlock.Hash(), "drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash()) blockReorgAddMeter.Mark(int64(len(newChain))) diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go index a69d83055..c163abfc5 100644 --- a/core/rawdb/freezer.go +++ b/core/rawdb/freezer.go @@ -284,7 +284,9 @@ func (f *freezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (writeSize if err != nil { return 0, err } + //begin PluGeth code injection pluginCommitUpdate(item) + //end PluGeth code injection atomic.StoreUint64(&f.frozen, item) return writeSize, nil } diff --git a/core/state/statedb.go b/core/state/statedb.go index df2d93dca..1b68bc341 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -151,6 +151,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) sdb.snapStorage = make(map[common.Hash]map[common.Hash][]byte) } } + // Start PluGeth section if sdb.snap == nil { log.Debug("Snapshots not availble. Using plugin snapshot.") sdb.snap = &pluginSnapshot{root} @@ -158,6 +159,7 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) sdb.snapAccounts = make(map[common.Hash][]byte) sdb.snapStorage = make(map[common.Hash]map[common.Hash][]byte) } + // End PluGeth section return sdb, nil } @@ -891,6 +893,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash { func (s *StateDB) Prepare(thash common.Hash, ti int) { s.thash = thash s.txIndex = ti + s.accessList = newAccessList() } func (s *StateDB) clearJournalAndRefund() { @@ -976,8 +979,10 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { } // Only update if there's a state transition (skip empty Clique blocks) if parent := s.snap.Root(); parent != root { + //begin PluGeth code injection pluginStateUpdate(root, parent, s.snapDestructs, s.snapAccounts, s.snapStorage, codeUpdates) - if _, ok := s.snap.(*pluginSnapshot); !ok && s.snaps != nil { + if _, ok := s.snap.(*pluginSnapshot); !ok && s.snaps != nil { // This if statement (but not its content) was added by PluGeth + //end PluGeth injection if err := s.snaps.Update(root, parent, s.snapDestructs, s.snapAccounts, s.snapStorage); err != nil { log.Warn("Failed to update snapshot tree", "from", parent, "to", root, "err", err) } diff --git a/core/state_processor.go b/core/state_processor.go index a7903cb96..56263838e 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -71,6 +71,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg misc.ApplyDAOHardFork(statedb) } blockContext := NewEVMBlockContext(header, p.bc, nil) + //begin PluGeth code injection blockTracer, ok := pluginGetBlockTracer(header.Hash(), statedb) if ok { cfg.Tracer = blockTracer @@ -104,6 +105,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // Finalize the block, applying any consensus engine specific extras (e.g. block rewards) p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles()) pluginPostProcessBlock(block) + //begin PluGeth code injection blockTracer.PostProcessBlock(block) return receipts, allLogs, *usedGas, nil } diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 523eb9177..06f707fa1 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -881,7 +881,9 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex } } // Get the tracer from the plugin loader + //begin PluGeth code injection if tr, ok := getPluginTracer(*config.Tracer); ok { + //end PluGeth code injection tracer = tr(statedb, vmctx) } else { // Constuct the JavaScript tracer to execute with diff --git a/rpc/handler.go b/rpc/handler.go index 776a887d7..b430eddfb 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -334,7 +334,9 @@ func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage return msg.errorResponse(&invalidParamsError{err.Error()}) } + //begin PluGeth code injection pluginGetRPCCalls(string(msg.ID), string(msg.Method), string(msg.Params)) + //begin PluGeth code injection start := time.Now() answer := h.runMethod(cp.ctx, msg, callb, args) diff --git a/rpc/service.go b/rpc/service.go index 6f0a0921e..00912213e 100644 --- a/rpc/service.go +++ b/rpc/service.go @@ -64,7 +64,9 @@ func (r *serviceRegistry) registerName(name string, rcvr interface{}) error { return fmt.Errorf("no service name for type %s", rcvrVal.Type().String()) } callbacks := suitableCallbacks(rcvrVal) + // begin PluGeth code injection pluginExtendedCallbacks(callbacks, rcvrVal) + // begin PluGeth code injection if len(callbacks) == 0 { return fmt.Errorf("service %T doesn't have any suitable methods/subscriptions to expose", rcvr) }