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

[Feature] merge state update to single transaction #258

Merged
merged 27 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,10 @@ func (b *Blockchain) executeBlockTransactions(block *types.Block) (*BlockResult,
return nil, ErrClosed
}

_, root := txn.Commit()
_, root, err := txn.Commit()
if err != nil {
return nil, err
}

// Append the receipts to the receipts cache
b.receiptsCache.Add(header.Hash, txn.Receipts())
Expand Down
2 changes: 1 addition & 1 deletion blockchain/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewTestBlockchain(t *testing.T, headers []*types.Header) *Blockchain {
},
}

st := itrie.NewState(itrie.NewMemoryStorage(), nil)
st := itrie.NewStateDB(itrie.NewMemoryStorage(), hclog.NewNullLogger(), nil)
b, err := newBlockChain(config, state.NewExecutor(config.Params, st, hclog.NewNullLogger()))

if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion command/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Config struct {
// Telemetry holds the config details for metric services.
type Telemetry struct {
PrometheusAddr string `json:"prometheus_addr"`
EnableIOTimer bool `json:"prometheus_enable_disk_io_timer"`
}

// Network defines the network configuration params
Expand Down Expand Up @@ -85,7 +86,9 @@ func DefaultConfig() *Config {
MaxOutboundPeers: defaultNetworkConfig.MaxOutboundPeers,
MaxInboundPeers: defaultNetworkConfig.MaxInboundPeers,
},
Telemetry: &Telemetry{},
Telemetry: &Telemetry{
EnableIOTimer: false,
},
ShouldSeal: false,
TxPool: &TxPool{
PriceLimit: 0,
Expand Down
2 changes: 2 additions & 0 deletions command/server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func (p *serverParams) initPrometheusAddress() error {
return parseErr
}

p.prometheusIOMetrics = p.rawConfig.Telemetry.EnableIOTimer

return nil
}

Expand Down
21 changes: 13 additions & 8 deletions command/server/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
leveldbNoSyncFlag = "leveldb.nosync"
libp2pAddressFlag = "libp2p"
prometheusAddressFlag = "prometheus"
enableIOTimerFlag = "prometheus-io-timer"
natFlag = "nat"
dnsFlag = "dns"
sealFlag = "seal"
Expand Down Expand Up @@ -83,13 +84,16 @@ type serverParams struct {
leveldbTotalTableSize int
leveldbNoSync bool

libp2pAddress *net.TCPAddr
prometheusAddress *net.TCPAddr
natAddress *net.TCPAddr
dnsAddress multiaddr.Multiaddr
grpcAddress *net.TCPAddr
jsonRPCAddress *net.TCPAddr
graphqlAddress *net.TCPAddr
libp2pAddress *net.TCPAddr

prometheusAddress *net.TCPAddr
prometheusIOMetrics bool

natAddress *net.TCPAddr
dnsAddress multiaddr.Multiaddr
grpcAddress *net.TCPAddr
jsonRPCAddress *net.TCPAddr
graphqlAddress *net.TCPAddr

blockGasTarget uint64
devInterval uint64
Expand Down Expand Up @@ -199,7 +203,8 @@ func (p *serverParams) generateConfig() *server.Config {
GRPCAddr: p.grpcAddress,
LibP2PAddr: p.libp2pAddress,
Telemetry: &server.Telemetry{
PrometheusAddr: p.prometheusAddress,
PrometheusAddr: p.prometheusAddress,
EnableIOMetrics: p.prometheusIOMetrics,
},
Network: &network.Config{
NoDiscover: p.rawConfig.Network.NoDiscover,
Expand Down
7 changes: 7 additions & 0 deletions command/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ func setFlags(cmd *cobra.Command) {
"the address and port for the prometheus instrumentation service (address:port). "+
"If only port is defined (:port) it will bind to 0.0.0.0:port",
)

cmd.Flags().BoolVar(
&params.rawConfig.Telemetry.EnableIOTimer,
enableIOTimerFlag,
false,
"enable IO timer metrics",
)
}

// txpool flags
Expand Down
5 changes: 4 additions & 1 deletion consensus/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ func (d *Dev) writeNewBlock(parent *types.Header) error {
txns := d.writeTransactions(gasLimit, transition)

// Commit the changes
_, root := transition.Commit()
_, root, err := transition.Commit()
if err != nil {
return err
}

// Update the header
header.StateRoot = root
Expand Down
6 changes: 5 additions & 1 deletion consensus/ibft/ibft.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,11 @@ func (i *Ibft) buildBlock(snap *Snapshot, parent *types.Header) (*types.Block, e
return nil, err
}

_, root := transition.Commit()
_, root, err := transition.Commit()
if err != nil {
return nil, err
}

header.StateRoot = root
header.GasUsed = transition.TotalGas()

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ require (
require go.uber.org/atomic v1.9.0

require (
github.com/VictoriaMetrics/fastcache v1.6.0
github.com/armon/go-radix v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v3 v3.0.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o=
github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw=
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
Expand All @@ -66,6 +68,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down Expand Up @@ -1392,6 +1396,7 @@ golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
8 changes: 6 additions & 2 deletions reverify/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ func createConsensus(
func createBlockchain(
logger hclog.Logger,
genesis *chain.Chain,
st *itrie.State,
st itrie.StateDB,
dataDir string,
) (*blockchain.Blockchain, consensus.Consensus, error) {
executor := state.NewExecutor(genesis.Params, st, logger)
executor.SetRuntime(precompiled.NewPrecompiled())
executor.SetRuntime(evm.NewEVM())

genesisRoot := executor.WriteGenesis(genesis.Genesis.Alloc)
genesisRoot, err := executor.WriteGenesis(genesis.Genesis.Alloc)
if err != nil {
return nil, nil, err
}

genesis.Genesis.StateRoot = genesisRoot

chain, err := blockchain.NewBlockchain(
Expand Down
2 changes: 1 addition & 1 deletion reverify/reverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ReverifyChain(
blockchain, consensus, err := createBlockchain(
logger,
chain,
itrie.NewState(stateStorage, nil),
itrie.NewStateDB(stateStorage, hclog.NewNullLogger(), itrie.NilMetrics()),
dataDir,
)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ type LeveldbOptions struct {

// Telemetry holds the config details for metric services
type Telemetry struct {
PrometheusAddr *net.TCPAddr
PrometheusAddr *net.TCPAddr
EnableIOMetrics bool
}

// JSONRPC holds the config details for the JSON-RPC server
Expand Down
12 changes: 8 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ func NewServer(config *Config) (*Server, error) {
}

if config.Telemetry.PrometheusAddr != nil {
m.serverMetrics = metricProvider("dogechain", config.Chain.Name, true)
m.serverMetrics = metricProvider("dogechain", config.Chain.Name, true, config.Telemetry.EnableIOMetrics)
m.prometheusServer = m.startPrometheusServer(config.Telemetry.PrometheusAddr)
} else {
m.serverMetrics = metricProvider("dogechain", config.Chain.Name, false)
m.serverMetrics = metricProvider("dogechain", config.Chain.Name, false, false)
}

// Set up the secrets manager
Expand Down Expand Up @@ -221,15 +221,19 @@ func NewServer(config *Config) (*Server, error) {

m.stateStorage = stateStorage

st := itrie.NewState(stateStorage, m.serverMetrics.trie)
st := itrie.NewStateDB(stateStorage, logger, m.serverMetrics.trie)
m.state = st

m.executor = state.NewExecutor(config.Chain.Params, st, logger)
m.executor.SetRuntime(precompiled.NewPrecompiled())
m.executor.SetRuntime(evm.NewEVM())

// compute the genesis root state
genesisRoot := m.executor.WriteGenesis(config.Chain.Genesis.Alloc)
genesisRoot, err := m.executor.WriteGenesis(config.Chain.Genesis.Alloc)
if err != nil {
return nil, err
}

config.Chain.Genesis.StateRoot = genesisRoot

// create leveldb storageBuilder
Expand Down
6 changes: 3 additions & 3 deletions server/server_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ type serverMetrics struct {
network *network.Metrics
txpool *txpool.Metrics
jsonrpc *jsonrpc.Metrics
trie *itrie.Metrics
trie itrie.Metrics
}

// metricProvider serverMetric instance for the given ChainID and nameSpace
func metricProvider(nameSpace string, chainID string, metricsRequired bool) *serverMetrics {
func metricProvider(nameSpace string, chainID string, metricsRequired bool, trackingIOTimer bool) *serverMetrics {
if metricsRequired {
return &serverMetrics{
blockchain: blockchain.GetPrometheusMetrics(nameSpace, "chain_id", chainID),
consensus: consensus.GetPrometheusMetrics(nameSpace, "chain_id", chainID),
network: network.GetPrometheusMetrics(nameSpace, "chain_id", chainID),
txpool: txpool.GetPrometheusMetrics(nameSpace, "chain_id", chainID),
jsonrpc: jsonrpc.GetPrometheusMetrics(nameSpace, "chain_id", chainID),
trie: itrie.GetPrometheusMetrics(nameSpace, "chain_id", chainID),
trie: itrie.GetPrometheusMetrics(nameSpace, trackingIOTimer, "chain_id", chainID),
}
}

Expand Down
Loading