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

[Non-breaking changes] Move statedb.Account struct to types.StateAccoun #7

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e0776fb
Move database_util.go to rawdb package
trinhdn97 Jul 20, 2023
5ce901b
Move db keys to schema.go
trinhdn97 Jul 20, 2023
36373e7
Refine db keys
trinhdn97 Jul 20, 2023
6392afd
Rename
trinhdn97 Jul 20, 2023
cf62b98
Split into sub accessor files
trinhdn97 Jul 20, 2023
dbccf9c
Init VRC25Issuer in genesis using puppeth wizard
trinhdn97 Dec 8, 2023
13b2f53
Merge pull request #407 from trinhdn2/update/puppeth_for_testnet_2023
tungng98 Dec 10, 2023
5e0692e
Define testnet fork blocks and special SMC addresses
trinhdn97 Dec 11, 2023
e12f32a
Merge pull request #411 from trinhdn2/cleanup/testnet_hardcode
tungng98 Dec 11, 2023
0ab845f
Add hardfork checkpoints utility functions to params.ChainConfig
trinhdn97 Dec 12, 2023
ebd4c5d
Allow puppeth wizard to modify genesis hardfork checkpoints
trinhdn97 Dec 12, 2023
72adad0
Respect current hardfork checkpoints constants
trinhdn97 Dec 12, 2023
39d768f
remove IsTestnet unused side effects
tungng98 Dec 13, 2023
0ac0159
Merge pull request #413 from tungng98/cleanup/remove-old-testnet-config
tungng98 Dec 13, 2023
07fb994
Merge remote-tracking branch 'origin/master' into ft/unify_hardforks_…
trinhdn97 Dec 13, 2023
ccb6513
Merge pull request #412 from trinhdn2/ft/unify_hardforks_chain_config
tungng98 Dec 13, 2023
9496c20
Bump go version to 1.19
trinhdn97 Dec 18, 2023
53c13e6
Merge pull request #417 from trinhdn2/update/bump_go_version
tungng98 Dec 18, 2023
a52b854
Feat: update version of duktape
imterryyy Dec 19, 2023
3c08aac
Feat: update go 1.21
imterryyy Dec 19, 2023
a1ab61c
fix(ci.go): ignore buildvcs
imterryyy Dec 19, 2023
c03863c
fix(crypto/bn256/cloudflare): pull in upstream fix for Go 1.21 R18
imterryyy Dec 19, 2023
21a87cf
remove buildvcs flag
imterryyy Dec 19, 2023
27ee58e
Merge pull request #418 from terryyyz-coin98/master
tungng98 Dec 19, 2023
9bd8b5a
Merge pull request #419 from trinhdn2/refactor/rawdb
tungng98 Dec 20, 2023
b9f81d5
Move statedb.Account struct to types.StateAccount
trinhdn97 Dec 27, 2023
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
4 changes: 0 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
**/.git
.git
!.git/HEAD
!.git/refs/heads
**/*_test.go

build/_workspace
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-alpine as builder
FROM golang:1.21-alpine as builder

RUN apk add --no-cache make gcc musl-dev linux-headers git

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.bootnode
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.11-alpine as builder
FROM golang:1.19-alpine as builder

RUN apk add --no-cache make gcc musl-dev linux-headers

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.node
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12-alpine as builder
FROM golang:1.19-alpine as builder

RUN apk add --no-cache make gcc musl-dev linux-headers git

Expand Down
14 changes: 7 additions & 7 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"context"
"errors"
"fmt"
"github.com/tomochain/tomochain/consensus"
"github.com/tomochain/tomochain/core/rawdb"
"math/big"
"sync"
"time"
Expand All @@ -30,9 +28,11 @@ import (
"github.com/tomochain/tomochain/accounts/abi/bind"
"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/common/math"
"github.com/tomochain/tomochain/consensus"
"github.com/tomochain/tomochain/consensus/ethash"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/core/bloombits"
"github.com/tomochain/tomochain/core/rawdb"
"github.com/tomochain/tomochain/core/state"
"github.com/tomochain/tomochain/core/types"
"github.com/tomochain/tomochain/core/vm"
Expand Down 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)
return receipt, nil
}

Expand Down Expand Up @@ -202,7 +202,7 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call tomochain.Call
return rval, err
}

//FIXME: please use copyState for this function
// FIXME: please use copyState for this function
// CallContractWithState executes a contract call at the given state.
func (b *SimulatedBackend) CallContractWithState(call tomochain.CallMsg, chain consensus.ChainContext, statedb *state.StateDB) ([]byte, error) {
// Ensure message is initialized properly.
Expand Down Expand Up @@ -285,7 +285,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call tomochain.CallM

snapshot := b.pendingState.Snapshot()
_, _, failed, err := b.callContract(ctx, call, b.pendingBlock, b.pendingState)
fmt.Println("EstimateGas",err,failed)
fmt.Println("EstimateGas", err, failed)
b.pendingState.RevertToSnapshot(snapshot)

if err != nil || failed {
Expand Down Expand Up @@ -485,11 +485,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)), 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))
if receipts == nil {
return nil, nil
}
Expand Down
12 changes: 6 additions & 6 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

//go:build none
// +build none

/*
Expand All @@ -23,14 +24,13 @@ Usage: go run build/ci.go <command> <command flags/arguments>

Available commands are:

install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
test [ -coverage ] [ packages... ] -- runs the tests
lint -- runs certain pre-selected linters
importkeys -- imports signing keys from env
xgo [ -alltools ] [ options ] -- cross builds according to options
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
test [ -coverage ] [ packages... ] -- runs the tests
lint -- runs certain pre-selected linters
importkeys -- imports signing keys from env
xgo [ -alltools ] [ options ] -- cross builds according to options

For all commands, -n prevents execution of external programs (dry run mode).

*/
package main

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
76 changes: 71 additions & 5 deletions cmd/puppeth/wizard_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
blockSignerContract "github.com/tomochain/tomochain/contracts/blocksigner"
multiSignWalletContract "github.com/tomochain/tomochain/contracts/multisigwallet"
randomizeContract "github.com/tomochain/tomochain/contracts/randomize"
vrc25Issuer "github.com/tomochain/tomochain/contracts/trc21issuer"
validatorContract "github.com/tomochain/tomochain/contracts/validator"
"github.com/tomochain/tomochain/crypto"
"github.com/tomochain/tomochain/rlp"
Expand All @@ -51,11 +52,20 @@ func (w *wizard) makeGenesis() {
Difficulty: big.NewInt(524288),
Alloc: make(core.GenesisAlloc),
Config: &params.ChainConfig{
HomesteadBlock: big.NewInt(1),
EIP150Block: big.NewInt(2),
EIP155Block: big.NewInt(3),
EIP158Block: big.NewInt(3),
ByzantiumBlock: big.NewInt(4),
HomesteadBlock: big.NewInt(0),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
TIP2019Block: big.NewInt(0),
TIPSigningBlock: big.NewInt(0),
TIPRandomizeBlock: big.NewInt(0),
BlackListHFBlock: big.NewInt(0),
TIPTRC21FeeBlock: big.NewInt(0),
TIPTomoXBlock: big.NewInt(0),
TIPTomoXLendingBlock: big.NewInt(0),
TIPTomoXCancellationFeeBlock: big.NewInt(0),
},
}
// Figure out which consensus engine to choose
Expand Down Expand Up @@ -311,6 +321,26 @@ func (w *wizard) makeGenesis() {
Storage: storage,
}

// VRC25 Issuer Smart Contract
tenVIC, ok := new(big.Int).SetString("10000000000000000000", 10)
if !ok {
fmt.Println("Can't convert 10 VIC for VRC25Issuer SMC")
}
vrc25IssuerAddress, _, err := vrc25Issuer.DeployTRC21Issuer(transactOpts, contractBackend, tenVIC)
if err != nil {
fmt.Println("Can't deploy VRC25Issuer SMC")
}
contractBackend.Commit()

code, _ = contractBackend.CodeAt(ctx, vrc25IssuerAddress, nil)
storage = make(map[common.Hash]common.Hash)
contractBackend.ForEachStorageAt(ctx, vrc25IssuerAddress, nil, f)
genesis.Alloc[common.TRC21IssuerSMC] = core.GenesisAccount{
Balance: big.NewInt(0),
Code: code,
Storage: storage,
}

fmt.Println()
fmt.Println("What is swap wallet address for fund 55m tomo?")
swapAddr := *w.readAddress()
Expand Down Expand Up @@ -386,6 +416,42 @@ func (w *wizard) manageGenesis() {
fmt.Printf("Which block should Byzantium come into effect? (default = %v)\n", w.conf.Genesis.Config.ByzantiumBlock)
w.conf.Genesis.Config.ByzantiumBlock = w.readDefaultBigInt(w.conf.Genesis.Config.ByzantiumBlock)

fmt.Println()
fmt.Printf("Which block should Constantinople come into effect? (default = %v)\n", w.conf.Genesis.Config.ConstantinopleBlock)
w.conf.Genesis.Config.ConstantinopleBlock = w.readDefaultBigInt(w.conf.Genesis.Config.ConstantinopleBlock)

fmt.Println()
fmt.Printf("Which block should TIP2019 come into effect? (default = %v)\n", w.conf.Genesis.Config.TIP2019Block)
w.conf.Genesis.Config.TIP2019Block = w.readDefaultBigInt(w.conf.Genesis.Config.TIP2019Block)

fmt.Println()
fmt.Printf("Which block should TIP signing come into effect? (default = %v)\n", w.conf.Genesis.Config.TIPSigningBlock)
w.conf.Genesis.Config.TIPSigningBlock = w.readDefaultBigInt(w.conf.Genesis.Config.TIPSigningBlock)

fmt.Println()
fmt.Printf("Which block should TIP Randomize come into effect? (default = %v)\n", w.conf.Genesis.Config.TIPRandomizeBlock)
w.conf.Genesis.Config.TIPRandomizeBlock = w.readDefaultBigInt(w.conf.Genesis.Config.TIPRandomizeBlock)

fmt.Println()
fmt.Printf("Which block should Blacklist hard fork come into effect? (default = %v)\n", w.conf.Genesis.Config.BlackListHFBlock)
w.conf.Genesis.Config.BlackListHFBlock = w.readDefaultBigInt(w.conf.Genesis.Config.BlackListHFBlock)

fmt.Println()
fmt.Printf("Which block should TIP TRC21 fee come into effect? (default = %v)\n", w.conf.Genesis.Config.TIPTRC21FeeBlock)
w.conf.Genesis.Config.TIPTRC21FeeBlock = w.readDefaultBigInt(w.conf.Genesis.Config.TIPTRC21FeeBlock)

fmt.Println()
fmt.Printf("Which block should TIP TomoX come into effect? (default = %v)\n", w.conf.Genesis.Config.TIPTomoXBlock)
w.conf.Genesis.Config.TIPTomoXBlock = w.readDefaultBigInt(w.conf.Genesis.Config.TIPTomoXBlock)

fmt.Println()
fmt.Printf("Which block should TIP TomoX Lending come into effect? (default = %v)\n", w.conf.Genesis.Config.TIPTomoXLendingBlock)
w.conf.Genesis.Config.TIPTomoXLendingBlock = w.readDefaultBigInt(w.conf.Genesis.Config.TIPTomoXLendingBlock)

fmt.Println()
fmt.Printf("Which block should TIP TomoX cancellation fee come into effect? (default = %v)\n", w.conf.Genesis.Config.TIPTomoXCancellationFeeBlock)
w.conf.Genesis.Config.TIPTomoXCancellationFeeBlock = w.readDefaultBigInt(w.conf.Genesis.Config.TIPTomoXCancellationFeeBlock)

out, _ := json.MarshalIndent(w.conf.Genesis.Config, "", " ")
fmt.Printf("Chain configuration updated:\n\n%s\n", out)

Expand Down
23 changes: 16 additions & 7 deletions cmd/tomo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"bufio"
"errors"
"fmt"
"gopkg.in/urfave/cli.v1"
"io"
"math/big"
"os"
"reflect"
"strings"
"unicode"

"gopkg.in/urfave/cli.v1"

"github.com/naoina/toml"
"github.com/tomochain/tomochain/cmd/utils"
"github.com/tomochain/tomochain/common"
Expand Down Expand Up @@ -156,14 +157,22 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
// Check testnet is enable.
if ctx.GlobalBool(utils.TomoTestnetFlag.Name) {
common.IsTestnet = true
common.TRC21IssuerSMC = common.TRC21IssuerSMCTestNet
cfg.Eth.NetworkId = 89
common.RelayerRegistrationSMC = common.RelayerRegistrationSMCTestnet
common.TIPTRC21Fee = common.TIPTomoXTestnet
common.TIPSigning = big.NewInt(0)
common.TIPRandomize = big.NewInt(0)

// Testnet hard fork blocks
common.TIP2019Block = big.NewInt(0)
common.BlackListHFNumber = uint64(0)
common.TIPSigningBlock = big.NewInt(0)
common.TIPRandomizeBlock = big.NewInt(0)
common.BlackListHFNumberBlock = uint64(0)
common.TIPTRC21FeeBlock = big.NewInt(0)
common.TIPTomoXBlock = big.NewInt(0)
common.TIPTomoXLendingBlock = big.NewInt(0)
common.TIPTomoXCancellationFeeBlock = big.NewInt(0)

// Special SMC addresses
common.LendingRegistrationSMC = common.LendingRegistrationSMCTestnet
common.RelayerRegistrationSMC = common.RelayerRegistrationSMCTestnet
common.TomoXListingSMC = common.TomoXListingSMCTestNet
}

// Rewound
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
Loading