Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add search api #1050

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (b *BlockGen) addTx(bc *BlockChain, vmConfig vm.Config, tx *types.Transacti
}

b.statedb.SetTxContext(tx.Hash(), len(b.txs))
receipt, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vmConfig, nil)
receipt, _, err := ApplyTransaction(b.config, bc, &b.header.Coinbase, b.gasPool, b.statedb, b.header, tx, &b.header.GasUsed, vmConfig, nil)

if err != nil {
panic(err)
Expand Down
7 changes: 7 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ const NoncePath = 2
const CodePath = 3
const SuicidePath = 4

// PrepareLegacy sets the current transaction hash and index which are
// used when the EVM emits new state logs.
func (s *StateDB) PrepareLegacy(thash common.Hash, ti int) {
s.thash = thash
s.txIndex = ti
}

// GetBalance retrieves the balance from the given address or 0 if object not found
func (s *StateDB) GetBalance(addr common.Address) *big.Int {
return MVRead(s, blockstm.NewSubpathKey(addr, BalancePath), common.Big0, func(s *StateDB) *big.Int {
Expand Down
15 changes: 7 additions & 8 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg

statedb.SetTxContext(tx.Hash(), i)

receipt, err := applyTransaction(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, interruptCtx)
receipt, _, err := applyTransaction(msg, p.config, gp, statedb, blockNumber, blockHash, tx, usedGas, vmenv, interruptCtx)
if err != nil {
return nil, nil, 0, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
Expand All @@ -115,7 +115,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
}

// nolint : unparam
func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, interruptCtx context.Context) (*types.Receipt, error) {
func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, statedb *state.StateDB, blockNumber *big.Int, blockHash common.Hash, tx *types.Transaction, usedGas *uint64, evm *vm.EVM, interruptCtx context.Context) (*types.Receipt, *ExecutionResult, error) {
// Create a new context to be used in the EVM environment.
txContext := NewEVMTxContext(msg)
evm.Reset(txContext, statedb)
Expand All @@ -136,7 +136,7 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta

result, err = ApplyMessageNoFeeBurnOrTip(evm, *msg, gp, interruptCtx)
if err != nil {
return nil, err
return nil, nil, err
}

// stop recording read and write
Expand Down Expand Up @@ -167,7 +167,7 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
)

if result.Err == vm.ErrInterrupt {
return nil, result.Err
return nil, nil, result.Err
}

// Update the state with pending changes.
Expand Down Expand Up @@ -205,21 +205,20 @@ func applyTransaction(msg *Message, config *params.ChainConfig, gp *GasPool, sta
receipt.BlockNumber = blockNumber
receipt.TransactionIndex = uint(statedb.TxIndex())

return receipt, err
return receipt, result, err
}

// ApplyTransaction attempts to apply a transaction to the given state database
// and uses the input parameters for its environment. It returns the receipt
// for the transaction, gas used and an error if the transaction failed,
// indicating the block was invalid.
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, interruptCtx context.Context) (*types.Receipt, error) {
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config, interruptCtx context.Context) (*types.Receipt, *ExecutionResult, error) {
msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number), header.BaseFee)
if err != nil {
return nil, err
return nil, nil, err
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)

return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv, interruptCtx)
}
5 changes: 3 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (s *Ethereum) PeerCount() int {
// APIs return the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API {
apis := ethapi.GetAPIs(s.APIBackend)
apis := ethapi.GetAPIs(s.APIBackend, s.blockchain)

// Append any APIs exposed explicitly by the consensus engine
apis = append(apis, s.engine.APIs(s.BlockChain())...)
Expand All @@ -388,7 +388,8 @@ func (s *Ethereum) APIs() []rpc.API {
{
Namespace: "eth",
Service: NewEthereumAPI(s),
}, {
},
{
Namespace: "miner",
Service: NewMinerAPI(s),
}, {
Expand Down
5 changes: 4 additions & 1 deletion eth/tracers/api_bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T
if err != nil {
return &TxTraceResult{
Error: err.Error(),
Result: &ethapi.ExecutionResult{
StructLogs: ethapi.FormatLogs(tracer.StructLogs()),
},
}
}

Expand Down Expand Up @@ -143,7 +146,7 @@ type TraceBlockRequest struct {
Config *TraceConfig
}

// If you use context as first parameter this function gets exposed automaticall on rpc endpoint
// TraceBorBlock If you use context as first parameter this function gets exposed automaticall on rpc endpoint
func (api *API) TraceBorBlock(req *TraceBlockRequest) (*BlockTraceResult, error) {
ctx := context.Background()

Expand Down
11 changes: 6 additions & 5 deletions eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func newCallTracer(ctx *tracers.Context, cfg json.RawMessage) (tracers.Tracer, e
return nil, err
}
}
config.WithLog = true
// First callframe contains tx context info
// and is populated on start and end.
return &callTracer{callstack: make([]callFrame, 1), config: config}, nil
Expand Down Expand Up @@ -156,9 +157,9 @@ func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
func (t *callTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
// skip if the previous op caused an error
if err != nil {
return
}
//if err != nil {
// return
//}
// Only logs need to be captured via opcode processing
if !t.config.WithLog {
return
Expand Down Expand Up @@ -187,7 +188,7 @@ func (t *callTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, sco

for i := 0; i < size; i++ {
topic := stackData[len(stackData)-2-(i+1)]
topics[i] = common.Hash(topic.Bytes32())
topics[i] = topic.Bytes32()
}

data, err := tracers.GetMemoryCopyPadded(scope.Memory, int64(mStart.Uint64()), int64(mSize.Uint64()))
Expand Down Expand Up @@ -252,7 +253,7 @@ func (t *callTracer) CaptureTxEnd(restGas uint64) {
t.callstack[0].GasUsed = t.gasLimit - restGas
if t.config.WithLog {
// Logs are not emitted when the call fails
clearFailedLogs(&t.callstack[0], false)
//clearFailedLogs(&t.callstack[0], false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/supranational/blst v0.3.11
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15
github.com/tendermint/tendermint v0.34.21
github.com/tyler-smith/go-bip39 v1.1.0
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
Expand Down Expand Up @@ -226,7 +227,6 @@ require (
github.com/streadway/amqp v1.0.0 // indirect
github.com/stumble/gorocksdb v0.0.3 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tendermint/iavl v0.12.4 // indirect
github.com/tendermint/tm-db v0.6.7 // indirect
Expand Down
Loading