Skip to content

Commit

Permalink
Merge branch 'develop' into feat/update-trie-to-stacktrie
Browse files Browse the repository at this point in the history
  • Loading branch information
trinhdn2 committed Aug 1, 2023
2 parents 260f47e + 475b70a commit 25f9c44
Show file tree
Hide file tree
Showing 84 changed files with 1,344 additions and 1,249 deletions.
38 changes: 27 additions & 11 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (b *SimulatedBackend) ForEachStorageAt(ctx context.Context, contract common

// TransactionReceipt returns the receipt of a transaction.
func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) {
receipt, _, _, _ := core.GetReceipt(b.database, txHash)
receipt, _, _, _ := rawdb.GetReceipt(b.database, txHash, b.config)
return receipt, nil
}

Expand Down Expand Up @@ -215,11 +215,19 @@ func (b *SimulatedBackend) CallContractWithState(call tomochain.CallMsg, chain c
call.Value = new(big.Int)
}
// Execute the call.
msg := callmsg{call}
msg := &core.Message{
To: call.To,
From: call.From,
Value: call.Value,
GasLimit: call.Gas,
GasPrice: call.GasPrice,
Data: call.Data,
SkipAccountChecks: false,
}
feeCapacity := state.GetTRC21FeeCapacityFromState(statedb)
if msg.To() != nil {
if value, ok := feeCapacity[*msg.To()]; ok {
msg.CallMsg.BalanceTokenFee = value
if msg.To != nil {
if value, ok := feeCapacity[*msg.To]; ok {
msg.BalanceTokenFee = value
}
}
evmContext := core.NewEVMContext(msg, chain.CurrentHeader(), chain, nil)
Expand Down Expand Up @@ -327,11 +335,19 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call tomochain.Call
from := statedb.GetOrNewStateObject(call.From)
from.SetBalance(math.MaxBig256)
// Execute the call.
msg := callmsg{call}
msg := &core.Message{
To: call.To,
From: call.From,
Value: call.Value,
GasLimit: call.Gas,
GasPrice: call.GasPrice,
Data: call.Data,
SkipAccountChecks: true,
}
feeCapacity := state.GetTRC21FeeCapacityFromState(statedb)
if msg.To() != nil {
if value, ok := feeCapacity[*msg.To()]; ok {
msg.CallMsg.BalanceTokenFee = value
if msg.To != nil {
if value, ok := feeCapacity[*msg.To]; ok {
msg.BalanceTokenFee = value
}
}
evmContext := core.NewEVMContext(msg, block.Header(), b.blockchain, nil)
Expand Down Expand Up @@ -484,11 +500,11 @@ func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumb
}

func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) {
return core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash)), nil
return rawdb.GetBlockReceipts(fb.db, hash, rawdb.GetBlockNumber(fb.db, hash), fb.bc.Config()), nil
}

func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error) {
receipts := core.GetBlockReceipts(fb.db, hash, core.GetBlockNumber(fb.db, hash))
receipts := rawdb.GetBlockReceipts(fb.db, hash, rawdb.GetBlockNumber(fb.db, hash), fb.bc.Config())
if receipts == nil {
return nil, nil
}
Expand Down
8 changes: 4 additions & 4 deletions accounts/keystore/keystore_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (w *keystoreWallet) SignHash(account accounts.Account, hash []byte) ([]byte
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
return nil, accounts.ErrUnknownAccount
}
// Account seems valid, request the keystore to sign
// StateAccount seems valid, request the keystore to sign
return w.keystore.SignHash(account, hash)
}

Expand All @@ -106,7 +106,7 @@ func (w *keystoreWallet) SignTx(account accounts.Account, tx *types.Transaction,
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
return nil, accounts.ErrUnknownAccount
}
// Account seems valid, request the keystore to sign
// StateAccount seems valid, request the keystore to sign
return w.keystore.SignTx(account, tx, chainID)
}

Expand All @@ -120,7 +120,7 @@ func (w *keystoreWallet) SignHashWithPassphrase(account accounts.Account, passph
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
return nil, accounts.ErrUnknownAccount
}
// Account seems valid, request the keystore to sign
// StateAccount seems valid, request the keystore to sign
return w.keystore.SignHashWithPassphrase(account, passphrase, hash)
}

Expand All @@ -134,6 +134,6 @@ func (w *keystoreWallet) SignTxWithPassphrase(account accounts.Account, passphra
if account.URL != (accounts.URL{}) && account.URL != w.account.URL {
return nil, accounts.ErrUnknownAccount
}
// Account seems valid, request the keystore to sign
// StateAccount seems valid, request the keystore to sign
return w.keystore.SignTxWithPassphrase(account, passphrase, tx, chainID)
}
2 changes: 1 addition & 1 deletion accounts/usbwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (w *wallet) selfDerive() {
// Termination requested
continue
case reqc = <-w.deriveReq:
// Account discovery requested
// StateAccount discovery requested
}
// Derivation needs a chain and device access, skip if either unavailable
w.stateLock.RLock()
Expand Down
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type faucet struct {
index []byte // Index page to serve up on the web

keystore *keystore.KeyStore // Keystore containing the single signer
account accounts.Account // Account funding user faucet requests
account accounts.Account // StateAccount funding user faucet requests
nonce uint64 // Current pending nonce of the faucet
price *big.Int // Current gas price to issue funds with

Expand Down
22 changes: 11 additions & 11 deletions cmd/gc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package main
import (
"flag"
"fmt"
"github.com/tomochain/tomochain/core/rawdb"
"github.com/tomochain/tomochain/ethdb"
"github.com/tomochain/tomochain/ethdb/leveldb"
"os"
"os/signal"
"runtime"
"sync"
"sync/atomic"
"time"

"github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru"

"github.com/tomochain/tomochain/cmd/utils"
"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/core/state"
"github.com/tomochain/tomochain/core/rawdb"
"github.com/tomochain/tomochain/core/types"
"github.com/tomochain/tomochain/eth"
"github.com/tomochain/tomochain/ethdb"
"github.com/tomochain/tomochain/ethdb/leveldb"
"github.com/tomochain/tomochain/rlp"
"github.com/tomochain/tomochain/trie"
)
Expand Down Expand Up @@ -54,15 +54,15 @@ func main() {
flag.Parse()
db, _ := leveldb.New(*dir, eth.DefaultConfig.DatabaseCache, utils.MakeDatabaseHandles(), "")
lddb := rawdb.NewDatabase(db)
head := core.GetHeadBlockHash(lddb)
currentHeader := core.GetHeader(lddb, head, core.GetBlockNumber(lddb, head))
head := rawdb.GetHeadBlockHash(lddb)
currentHeader := rawdb.GetHeader(lddb, head, rawdb.GetBlockNumber(lddb, head))
tridb := trie.NewDatabase(lddb)
catchEventInterupt(db)
cache, _ = lru.New(*cacheSize)
go func() {
for i := uint64(1); i <= currentHeader.Number.Uint64(); i++ {
hash := core.GetCanonicalHash(lddb, i)
root := core.GetHeader(lddb, hash, i).Root
hash := rawdb.GetCanonicalHash(lddb, i)
root := rawdb.GetHeader(lddb, hash, i).Root
trieRoot, err := trie.NewSecure(root, tridb)
if err != nil {
continue
Expand All @@ -82,7 +82,7 @@ func main() {
if running {
for _, address := range cleanAddress {
enc := trieRoot.trie.Get(address.Bytes())
var data state.Account
var data types.StateAccount
rlp.DecodeBytes(enc, &data)
fmt.Println(time.Now().Format(time.RFC3339), "Start clean state address ", address.Hex(), " at block ", trieRoot.number)
signerRoot, err := resolveHash(data.Root[:], db)
Expand Down
3 changes: 1 addition & 2 deletions cmd/tomo/bugcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,4 @@ const header = `Please answer these questions before submitting your issue. Than
#### What did you see instead?
#### System details
`
#### System details`
4 changes: 2 additions & 2 deletions cmd/tomo/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestConsoleWelcome(t *testing.T) {
tomo.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
tomo.SetTemplateFunc("gover", runtime.Version)
tomo.SetTemplateFunc("tomover", func() string { return params.Version })
tomo.SetTemplateFunc("niltime", func() string { return time.Unix(1544771829, 0).Format(time.RFC1123) })
tomo.SetTemplateFunc("niltime", func() string { return time.Unix(1544771829, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)") })
tomo.SetTemplateFunc("apis", func() string { return ipcAPIs })

// Verify the actual welcome message to the required template
Expand Down Expand Up @@ -137,7 +137,7 @@ func testAttachWelcome(t *testing.T, tomo *testtomo, endpoint, apis string) {
attach.SetTemplateFunc("gover", runtime.Version)
attach.SetTemplateFunc("tomover", func() string { return params.Version })
attach.SetTemplateFunc("etherbase", func() string { return tomo.Etherbase })
attach.SetTemplateFunc("niltime", func() string { return time.Unix(1544771829, 0).Format(time.RFC1123) })
attach.SetTemplateFunc("niltime", func() string { return time.Unix(1544771829, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)") })
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
attach.SetTemplateFunc("datadir", func() string { return tomo.Datadir })
attach.SetTemplateFunc("apis", func() string { return apis })
Expand Down
5 changes: 2 additions & 3 deletions cmd/tomo/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
package main

import (
"github.com/tomochain/tomochain/core/rawdb"
"io/ioutil"
"math/big"
"os"
"path/filepath"
"testing"

"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/core/rawdb"
)

// Genesis block for nodes which don't care about the DAO fork (i.e. not configured)
Expand Down Expand Up @@ -130,7 +129,7 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
if genesis != "" {
genesisHash = daoGenesisHash
}
config, err := core.GetChainConfig(db, genesisHash)
config, err := rawdb.GetChainConfig(db, genesisHash)
if err != nil {
t.Errorf("test %d: failed to retrieve chain config: %v", test, err)
return // we want to return here, the other checks can't make it past this point (nil panic).
Expand Down
5 changes: 3 additions & 2 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/core/rawdb"
"github.com/tomochain/tomochain/core/types"
"github.com/tomochain/tomochain/crypto"
"github.com/tomochain/tomochain/ethdb"
Expand Down Expand Up @@ -271,15 +272,15 @@ func ImportPreimages(db ethdb.Database, fn string) error {
// Accumulate the preimages and flush when enough ws gathered
preimages[crypto.Keccak256Hash(blob)] = common.CopyBytes(blob)
if len(preimages) > 1024 {
if err := core.WritePreimages(db, 0, preimages); err != nil {
if err := rawdb.WritePreimages(db, 0, preimages); err != nil {
return err
}
preimages = make(map[common.Hash][]byte)
}
}
// Flush the last batch preimage data
if len(preimages) > 0 {
return core.WritePreimages(db, 0, preimages)
return rawdb.WritePreimages(db, 0, preimages)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
type Vote struct {
Signer common.Address `json:"signer"` // Authorized signer that cast this vote
Block uint64 `json:"block"` // Block number the vote was cast in (expire old votes)
Address common.Address `json:"address"` // Account being voted on to change its authorization
Address common.Address `json:"address"` // StateAccount being voted on to change its authorization
Authorize bool `json:"authorize"` // Whether to authorize or deauthorize the voted account
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/posv/posv.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var (

// SignerFn is a signer callback function to request a hash to be signed by a
// backing account.
//type SignerFn func(accounts.Account, []byte) ([]byte, error)
//type SignerFn func(accounts.StateAccount, []byte) ([]byte, error)

// sigHash returns the hash which is used as input for the proof-of-stake-voting
// signing. It is the hash of the entire header apart from the 65 byte signature
Expand Down
2 changes: 1 addition & 1 deletion consensus/posv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
//type Vote struct {
// Signer common.Address `json:"signer"` // Authorized signer that cast this vote
// Block uint64 `json:"block"` // Block number the vote was cast in (expire old votes)
// Address common.Address `json:"address"` // Account being voted on to change its authorization
// Address common.Address `json:"address"` // StateAccount being voted on to change its authorization
// Authorize bool `json:"authorize"` // Whether to authorize or deauthorize the voted account
//}

Expand Down
15 changes: 8 additions & 7 deletions console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package console
import (
"bytes"
"errors"
"github.com/tomochain/tomochain/tomox"
"github.com/tomochain/tomochain/tomoxlending"
"io/ioutil"
"os"
"strings"
Expand All @@ -29,10 +27,13 @@ import (

"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/consensus/ethash"
"github.com/tomochain/tomochain/console/prompt"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/eth"
"github.com/tomochain/tomochain/internal/jsre"
"github.com/tomochain/tomochain/node"
"github.com/tomochain/tomochain/tomox"
"github.com/tomochain/tomochain/tomoxlending"
)

const (
Expand Down Expand Up @@ -67,10 +68,10 @@ func (p *hookedPrompter) PromptPassword(prompt string) (string, error) {
func (p *hookedPrompter) PromptConfirm(prompt string) (bool, error) {
return false, errors.New("not implemented")
}
func (p *hookedPrompter) SetHistory(history []string) {}
func (p *hookedPrompter) AppendHistory(command string) {}
func (p *hookedPrompter) ClearHistory() {}
func (p *hookedPrompter) SetWordCompleter(completer WordCompleter) {}
func (p *hookedPrompter) SetHistory(history []string) {}
func (p *hookedPrompter) AppendHistory(command string) {}
func (p *hookedPrompter) ClearHistory() {}
func (p *hookedPrompter) SetWordCompleter(completer prompt.WordCompleter) {}

// tester is a console test environment for the console tests to operate on.
type tester struct {
Expand Down Expand Up @@ -262,7 +263,7 @@ func TestPrettyError(t *testing.T) {
defer tester.Close(t)
tester.console.Evaluate("throw 'hello'")

want := jsre.ErrorColor("hello") + "\n"
want := jsre.ErrorColor("hello") + "\n\tat <eval>:1:1(1)\n\n"
if output := tester.output.String(); output != want {
t.Fatalf("pretty error mismatch: have %s, want %s", output, want)
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/tomochain/tomochain/contracts/blocksigner/contract"
randomizeContract "github.com/tomochain/tomochain/contracts/randomize/contract"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/core/rawdb"
"github.com/tomochain/tomochain/core/state"
stateDatabase "github.com/tomochain/tomochain/core/state"
"github.com/tomochain/tomochain/core/types"
Expand Down Expand Up @@ -336,7 +337,7 @@ func GetRewardForCheckpoint(c *posv.Posv, chain consensus.ChainReader, header *t
block := chain.GetBlock(header.Hash(), i)
txs := block.Transactions()
if !chain.Config().IsTIPSigning(header.Number) {
receipts := core.GetBlockReceipts(c.GetDb(), header.Hash(), i)
receipts := rawdb.GetBlockReceipts(c.GetDb(), header.Hash(), i, chain.Config())
signData = c.CacheData(header, txs, receipts)
} else {
signData = c.CacheSigner(header.Hash(), txs)
Expand Down
20 changes: 7 additions & 13 deletions core/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,13 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
ReceiptHash: types.EmptyRootHash,
}
hash = header.Hash()
WriteHeader(db, header)
WriteCanonicalHash(db, hash, n)
WriteTd(db, hash, n, big.NewInt(int64(n+1)))
if n == 0 {
WriteChainConfig(db, hash, params.AllEthashProtocolChanges)
}
WriteHeadHeaderHash(db, hash)

rawdb.WriteHeader(db, header)
rawdb.WriteCanonicalHash(db, hash, n)
rawdb.WriteTd(db, hash, n, big.NewInt(int64(n+1)))
if full || n == 0 {
block := types.NewBlockWithHeader(header)
WriteBody(db, hash, n, block.Body())
WriteBlockReceipts(db, hash, n, nil)
WriteHeadBlockHash(db, hash)
rawdb.WriteBody(db, hash, n, block.Body())
rawdb.WriteBlockReceipts(db, hash, n, nil)
}
}
}
Expand Down Expand Up @@ -302,8 +296,8 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
header := chain.GetHeaderByNumber(n)
if full {
hash := header.Hash()
GetBody(db, hash, n)
GetBlockReceipts(db, hash, n)
rawdb.GetBody(db, hash, n)
rawdb.GetBlockReceipts(db, hash, n, params.TestChainConfig)
}
}

Expand Down

0 comments on commit 25f9c44

Please sign in to comment.