Skip to content

Commit

Permalink
Merge branch 'release/api/1.0.1-rc.3' into release/txtracing/1.0.1-rc.2
Browse files Browse the repository at this point in the history
  • Loading branch information
uprendis committed Jun 18, 2021
2 parents 2aa0add + d30cb5b commit e0b6e0a
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 103 deletions.
8 changes: 4 additions & 4 deletions cmd/opera/launcher/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func overrideFlags() {

// NodeDefaultConfig contains reasonable default settings.
var NodeDefaultConfig = node.Config{
DataDir: DefaultDataDir(),
HTTPPort: DefaultHTTPPort,
HTTPModules: []string{},
HTTPVirtualHosts: []string{"localhost"},
DataDir: DefaultDataDir(),
HTTPPort: DefaultHTTPPort,
HTTPModules: []string{},
HTTPVirtualHosts: []string{"localhost"},
HTTPTimeouts: rpc.HTTPTimeouts{
ReadTimeout: 120 * time.Second,
IdleTimeout: 120 * time.Second,
Expand Down
16 changes: 16 additions & 0 deletions evmcore/dummy_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ type (
}
)

// NewEvmBlock constructor.
func NewEvmBlock(h *EvmHeader, txs types.Transactions) *EvmBlock {
b := &EvmBlock{
EvmHeader: *h,
Transactions: txs,
}

if len(txs) == 0 {
b.EvmHeader.TxHash = types.EmptyRootHash
} else {
b.EvmHeader.TxHash = types.DeriveSha(txs, new(trie.Trie))
}

return b
}

// ToEvmHeader converts inter.Block to EvmHeader.
func ToEvmHeader(block *inter.Block, index idx.Block, prevHash hash.Event) *EvmHeader {
return &EvmHeader{
Expand Down
14 changes: 7 additions & 7 deletions evmcore/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,6 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if !local && tx.GasPriceIntCmp(pool.gasPrice) < 0 {
return ErrUnderpriced
}
// Ensure Opera-specific hard bounds
if pool.chain.MinGasPrice().Cmp(tx.GasPrice()) > 0 {
return ErrUnderpriced
}
if pool.chain.TxExists(tx.Hash()) {
return ErrUnderpriced
}
// Ensure the transaction adheres to nonce ordering
if pool.currentState.GetNonce(from) > tx.Nonce() {
return ErrNonceTooLow
Expand All @@ -589,6 +582,13 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if tx.Gas() < intrGas {
return ErrIntrinsicGas
}
// Ensure Opera-specific hard bounds
if pool.chain.MinGasPrice().Cmp(tx.GasPrice()) > 0 {
return ErrUnderpriced
}
if pool.chain.TxExists(tx.Hash()) {
return ErrUnderpriced
}
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/google/uuid v1.1.1 // indirect
github.com/gorilla/websocket v1.4.1 // indirect
github.com/hashicorp/golang-lru v0.5.4
github.com/holiman/uint256 v1.1.1 // indirect
github.com/holiman/uint256 v1.1.1
github.com/influxdata/influxdb v1.7.9 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/karalabe/usb v0.0.0-20191104083709-911d15fe12a9 // indirect
Expand Down Expand Up @@ -54,6 +54,6 @@ require (
gopkg.in/urfave/cli.v1 v1.20.0
)

replace github.com/ethereum/go-ethereum => github.com/Fantom-foundation/go-ethereum v1.9.22-ftm-0.5
replace github.com/ethereum/go-ethereum => github.com/uprendis/go-ethereum v1.9.7-0.20210501212005-da4db6546f89

replace github.com/dvyukov/go-fuzz => github.com/guzenok/go-fuzz v0.0.0-20210103140116-f9104dfb626f
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Fantom-foundation/go-ethereum v1.9.22-ftm-0.5 h1:hyMHsRBFoBIjwur3LgyYa/Lm7WzJqnM7HtK7/vnSkeA=
github.com/Fantom-foundation/go-ethereum v1.9.22-ftm-0.5/go.mod h1:27ZY0H7YdbxCL0E/d23qHo9WCkjqnmFKHQl9UaUSw8s=
github.com/Fantom-foundation/lachesis-base v0.0.0-20210420092627-c16f01e35562 h1:SFcBjyI5dos9JeIRBHnzU88SlVTlEjRbAUrlZ40uWfk=
github.com/Fantom-foundation/lachesis-base v0.0.0-20210420092627-c16f01e35562/go.mod h1:E6+2LOvgADwSOv0U5YXhRJz4PlX8qJxvq8M93AOC1tM=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down Expand Up @@ -321,6 +319,8 @@ github.com/uber/jaeger-client-go v2.20.1+incompatible h1:HgqpYBng0n7tLJIlyT4kPCI
github.com/uber/jaeger-client-go v2.20.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.2.0+incompatible h1:MxZXOiR2JuoANZ3J6DE/U0kSFv/eJ/GfSYVCjK7dyaw=
github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/uprendis/go-ethereum v1.9.7-0.20210501212005-da4db6546f89 h1:XW6JOLMYwa2z8x3C8PO9uQkoRT8GLroBbLZLivJX9uM=
github.com/uprendis/go-ethereum v1.9.7-0.20210501212005-da4db6546f89/go.mod h1:27ZY0H7YdbxCL0E/d23qHo9WCkjqnmFKHQl9UaUSw8s=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 h1:1cngl9mPEoITZG8s8cVcUy5CeIBYhEESkOB7m6Gmkrk=
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees=
Expand Down
24 changes: 11 additions & 13 deletions gossip/blockproc/evmmodule/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@ type OperaEVMProcessor struct {
}

func (p *OperaEVMProcessor) evmBlockWith(txs types.Transactions) *evmcore.EvmBlock {
return &evmcore.EvmBlock{
EvmHeader: evmcore.EvmHeader{
Number: p.blockIdx,
Hash: common.Hash(p.block.Atropos),
ParentHash: p.prevBlockHash,
Root: common.Hash{},
TxHash: common.Hash{},
Time: p.block.Time,
Coinbase: common.Address{},
GasLimit: math.MaxUint64,
GasUsed: p.gasUsed,
},
Transactions: txs,
h := &evmcore.EvmHeader{
Number: p.blockIdx,
Hash: common.Hash(p.block.Atropos),
ParentHash: p.prevBlockHash,
Root: common.Hash{},
Time: p.block.Time,
Coinbase: common.Address{},
GasLimit: math.MaxUint64,
GasUsed: p.gasUsed,
}

return evmcore.NewEvmBlock(h, txs)
}

func (p *OperaEVMProcessor) Execute(txs types.Transactions, internal bool, cfg vm.Config) types.Receipts {
Expand Down
16 changes: 16 additions & 0 deletions gossip/c_block_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ func consensusCallbackBeginBlockFn(
block, blockEvents := spillBlockEvents(store, block, es.Rules)
txs := make(types.Transactions, 0, blockEvents.Len()*10)
for _, e := range blockEvents {
var renamedIdxs []uint32
var renamedHashes []common.Hash
for i, tx := range e.Txs() {
if store.EvmStore().GetTxPosition(tx.Hash()) != nil {
h := tx.Hash()
for i := 0; i < 32; i++ {
h[i] = ^h[i]
}
tx.SetHash(h)
renamedIdxs = append(renamedIdxs, uint32(i))
renamedHashes = append(renamedHashes, h)
}
}
if len(renamedIdxs) != 0 {
store.SetRenamedTxs(e.ID(), renamedIdxs, renamedHashes)
}
txs = append(txs, e.Txs()...)
}

Expand Down
20 changes: 7 additions & 13 deletions gossip/evm_state_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"

"github.com/Fantom-foundation/go-opera/evmcore"
"github.com/Fantom-foundation/go-opera/inter"
Expand Down Expand Up @@ -116,22 +115,17 @@ func (r *EvmStateReader) getBlock(h hash.Event, n idx.Block, readTxs bool) *evmc
}
evmHeader := evmcore.ToEvmHeader(block, n, prev)

var evmBlock *evmcore.EvmBlock
if readTxs {
if len(transactions) == 0 {
evmHeader.TxHash = types.EmptyRootHash
} else {
evmHeader.TxHash = types.DeriveSha(transactions, new(trie.Trie))
evmBlock = evmcore.NewEvmBlock(evmHeader, transactions)
r.store.EvmStore().SetCachedEvmBlock(n, evmBlock)
} else {
// not completed block here
evmBlock = &evmcore.EvmBlock{
EvmHeader: *evmHeader,
}
}

evmBlock := &evmcore.EvmBlock{
EvmHeader: *evmHeader,
Transactions: transactions,
}

if readTxs {
r.store.EvmStore().SetCachedEvmBlock(n, evmBlock)
}
return evmBlock
}

Expand Down
6 changes: 6 additions & 0 deletions gossip/evmstore/store_block_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package evmstore

import (
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/ethereum/go-ethereum/common"

"github.com/Fantom-foundation/go-opera/evmcore"
)
Expand All @@ -11,9 +12,14 @@ func (s *Store) GetCachedEvmBlock(n idx.Block) *evmcore.EvmBlock {
if !ok {
return nil
}

return c.(*evmcore.EvmBlock)
}

func (s *Store) SetCachedEvmBlock(n idx.Block, b *evmcore.EvmBlock) {
var empty = common.Hash{}
if b.EvmHeader.TxHash == empty {
panic("You have to cache only completed blocks (with txs)")
}
s.cache.EvmBlocks.Add(n, b, uint(b.EstimateSize()))
}
2 changes: 2 additions & 0 deletions gossip/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ func newService(config Config, store *Store, signer valkeystore.SignerI, blockPr

svc.emitter = svc.makeEmitter(signer)

svc.store.GetEventPayload(hash.ZeroEvent)

svc.verWatcher = verwatcher.New(config.VersionWatcher, verwatcher.NewStore(store.table.NetworkVersion))

return svc, nil
Expand Down
1 change: 1 addition & 0 deletions gossip/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Store struct {
// API-only
BlockHashes kvdb.Store `table:"B"`
SfcAPI kvdb.Store `table:"S"`
RenamedTxs kvdb.Store `table:"9"`
}

prevFlushTime time.Time
Expand Down
30 changes: 30 additions & 0 deletions gossip/store_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ package gossip
import (
"bytes"

"github.com/Fantom-foundation/lachesis-base/common/bigendian"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"

Expand Down Expand Up @@ -51,6 +53,22 @@ func (s *Store) GetEventPayload(id hash.Event) *inter.EventPayload {
key := id.Bytes()
w, _ := s.rlp.Get(s.table.Events, key, &inter.EventPayload{}).(*inter.EventPayload)

if w != nil {
if !w.NoTxs() {
renamed, err := s.table.RenamedTxs.Get(id.Bytes())
if err != nil {
s.Log.Crit("Failed to get key", "err", err)
}
if len(renamed) != 0 {
for i := 0; i < len(renamed); i += 36 {
index := bigendian.BytesToUint32(renamed[i : i+4])
h := common.BytesToHash(renamed[i+4 : i+4+32])
w.Txs()[index].SetHash(h)
}
}
}
}

// Put event to LRU cache.
if w != nil {
s.cache.Events.Add(id, w, uint(w.Size()))
Expand All @@ -61,6 +79,18 @@ func (s *Store) GetEventPayload(id hash.Event) *inter.EventPayload {
return w
}

func (s *Store) SetRenamedTxs(id hash.Event, idxs []uint32, hashes []common.Hash) {
b := bytes.NewBuffer(make([]byte, 0, len(idxs)*36))
for i := 0; i < len(idxs); i++ {
b.Write(bigendian.Uint32ToBytes(idxs[i]))
b.Write(hashes[i].Bytes())
}
err := s.table.RenamedTxs.Put(id.Bytes(), b.Bytes())
if err != nil {
s.Log.Crit("Failed to put key", "err", err)
}
}

// GetEvent returns stored event.
func (s *Store) GetEvent(id hash.Event) *inter.Event {
// Get event from LRU cache first.
Expand Down
5 changes: 1 addition & 4 deletions gossip/store_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ func (s *Store) migrateData() error {
versions.SetID(s.migrations().ID())
return nil
}
err := s.migrations().Exec(versions)
if err == nil {
err = s.Commit()
}

err := s.migrations().Exec(versions, s.Commit)
return err
}

Expand Down
4 changes: 2 additions & 2 deletions opera/genesis/evmwriter/evm_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (_ PreCompiledContract) Run(stateDB vm.StateDB, ctx vm.Context, caller comm
value := common.BytesToHash(input[:32])

stateDB.SetState(acc, key, value)
} else if bytes.Equal(input[:4], incNonceMethodID) {
} else if bytes.Equal(input[:4], incNonceMethodID) {
input = input[4:]
// incNonce
if suppliedGas < params.CallValueTransferGas {
Expand Down Expand Up @@ -194,7 +194,7 @@ func (_ PreCompiledContract) Run(stateDB vm.StateDB, ctx vm.Context, caller comm
return nil, 0, vm.ErrExecutionReverted
}

stateDB.SetNonce(acc, stateDB.GetNonce(acc) + value.Uint64())
stateDB.SetNonce(acc, stateDB.GetNonce(acc)+value.Uint64())
} else {
return nil, 0, vm.ErrExecutionReverted
}
Expand Down
24 changes: 11 additions & 13 deletions topicsdb/search_lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"github.com/ethereum/go-ethereum/common"
)

type logHandler func(rec *logrec, complete bool) (gonext bool, err error)
type logHandler func(rec *logrec) (gonext bool, err error)

func (tt *Index) searchLazy(ctx context.Context, pattern [][]common.Hash, blockStart []byte, onMatched logHandler) (err error) {
func (tt *Index) searchLazy(ctx context.Context, pattern [][]common.Hash, blockStart []byte, blockEnd uint64, onMatched logHandler) (err error) {
if ctx == nil {
ctx = context.Background()
}
_, err = tt.walkFirst(ctx, blockStart, pattern, 0, onMatched)
_, err = tt.walkFirst(ctx, blockStart, blockEnd, pattern, 0, onMatched)
return
}

// walkFirst for topics recursive.
func (tt *Index) walkFirst(
ctx context.Context, blockStart []byte, pattern [][]common.Hash, pos uint8, onMatched logHandler,
ctx context.Context, blockStart []byte, blockEnd uint64, pattern [][]common.Hash, pos uint8, onMatched logHandler,
) (
gonext bool, err error,
) {
Expand Down Expand Up @@ -59,13 +59,11 @@ func (tt *Index) walkFirst(
id := extractLogrecID(it.Key())
rec := newLogrec(id, topicCount)

gonext, err = onMatched(rec, false)
if err != nil || !gonext {
it.Release()
return
if blockEnd > 0 && rec.ID.BlockNumber() > blockEnd {
break
}

gonext, err = tt.walkNexts(ctx, rec, nil, pattern, pos+1, onMatched)
gonext, err = tt.walkNexts(ctx, rec, pattern, pos+1, onMatched)
if err != nil || !gonext {
it.Release()
return
Expand All @@ -84,7 +82,7 @@ func (tt *Index) walkFirst(

// walkNexts for topics recursive.
func (tt *Index) walkNexts(
ctx context.Context, rec *logrec, blockStart []byte, pattern [][]common.Hash, pos uint8, onMatched logHandler,
ctx context.Context, rec *logrec, pattern [][]common.Hash, pos uint8, onMatched logHandler,
) (
gonext bool, err error,
) {
Expand All @@ -93,7 +91,7 @@ func (tt *Index) walkNexts(
for {
// Max recursion depth is equal to len(topics) and limited by MaxCount.
if pos >= patternLen {
gonext, err = onMatched(rec, true)
gonext, err = onMatched(rec)
return
}
if len(pattern[pos]) < 1 {
Expand All @@ -114,15 +112,15 @@ func (tt *Index) walkNexts(

for _, variant := range pattern[pos] {
copy(prefix[0:], variant.Bytes())
it := tt.table.Topic.NewIterator(prefix[:prefLen], blockStart)
it := tt.table.Topic.NewIterator(prefix[:prefLen], nil)
for it.Next() {
err = ctx.Err()
if err != nil {
it.Release()
return
}

gonext, err = tt.walkNexts(ctx, rec, nil, pattern, pos+1, onMatched)
gonext, err = tt.walkNexts(ctx, rec, pattern, pos+1, onMatched)
if err != nil || !gonext {
it.Release()
return
Expand Down
Loading

0 comments on commit e0b6e0a

Please sign in to comment.