mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
all: fix log and err handling
This commit is contained in:
parent
19d8abb4d6
commit
d12c122507
4 changed files with 41 additions and 51 deletions
|
|
@ -47,6 +47,7 @@ func copyConfig(original *params.ChainConfig) *params.ChainConfig {
|
||||||
TerminalTotalDifficulty: original.TerminalTotalDifficulty,
|
TerminalTotalDifficulty: original.TerminalTotalDifficulty,
|
||||||
Ethash: original.Ethash,
|
Ethash: original.Ethash,
|
||||||
Clique: original.Clique,
|
Clique: original.Clique,
|
||||||
|
Eccpow: original.Eccpow,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import (
|
||||||
|
|
||||||
// Register adds the engine API to the full node.
|
// Register adds the engine API to the full node.
|
||||||
func Register(stack *node.Node, backend *eth.Ethereum) error {
|
func Register(stack *node.Node, backend *eth.Ethereum) error {
|
||||||
log.Warn("Engine API enabled", "protocol", "eth")
|
log.Warn("Engine API enabled", "protocol", "worldland")
|
||||||
stack.RegisterAPIs([]rpc.API{
|
stack.RegisterAPIs([]rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "engine",
|
Namespace: "engine",
|
||||||
|
|
@ -125,9 +125,10 @@ type ConsensusAPI struct {
|
||||||
// NewConsensusAPI creates a new consensus api for the given backend.
|
// NewConsensusAPI creates a new consensus api for the given backend.
|
||||||
// The underlying blockchain needs to have a valid terminal total difficulty set.
|
// The underlying blockchain needs to have a valid terminal total difficulty set.
|
||||||
func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
|
func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
|
||||||
|
/*
|
||||||
if eth.BlockChain().Config().TerminalTotalDifficulty == nil {
|
if eth.BlockChain().Config().TerminalTotalDifficulty == nil {
|
||||||
log.Warn("Engine API started but chain not configured for merge yet")
|
log.Warn("Engine API started but chain not configured for merge yet")
|
||||||
}
|
}*/
|
||||||
api := &ConsensusAPI{
|
api := &ConsensusAPI{
|
||||||
eth: eth,
|
eth: eth,
|
||||||
remoteBlocks: newHeaderQueue(),
|
remoteBlocks: newHeaderQueue(),
|
||||||
|
|
@ -143,21 +144,14 @@ func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
|
||||||
|
|
||||||
// ForkchoiceUpdatedV1 has several responsibilities:
|
// ForkchoiceUpdatedV1 has several responsibilities:
|
||||||
// If the method is called with an empty head block:
|
// If the method is called with an empty head block:
|
||||||
//
|
// we return success, which can be used to check if the engine API is enabled
|
||||||
// we return success, which can be used to check if the engine API is enabled
|
|
||||||
//
|
|
||||||
// If the total difficulty was not reached:
|
// If the total difficulty was not reached:
|
||||||
//
|
// we return INVALID
|
||||||
// we return INVALID
|
|
||||||
//
|
|
||||||
// If the finalizedBlockHash is set:
|
// If the finalizedBlockHash is set:
|
||||||
//
|
// we check if we have the finalizedBlockHash in our db, if not we start a sync
|
||||||
// we check if we have the finalizedBlockHash in our db, if not we start a sync
|
|
||||||
//
|
|
||||||
// We try to set our blockchain to the headBlock
|
// We try to set our blockchain to the headBlock
|
||||||
// If there are payloadAttributes:
|
// If there are payloadAttributes:
|
||||||
//
|
// we try to assemble a block with the payloadAttributes and return its payloadID
|
||||||
// we try to assemble a block with the payloadAttributes and return its payloadID
|
|
||||||
func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, payloadAttributes *beacon.PayloadAttributesV1) (beacon.ForkChoiceResponse, error) {
|
func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, payloadAttributes *beacon.PayloadAttributesV1) (beacon.ForkChoiceResponse, error) {
|
||||||
api.forkchoiceLock.Lock()
|
api.forkchoiceLock.Lock()
|
||||||
defer api.forkchoiceLock.Unlock()
|
defer api.forkchoiceLock.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -97,9 +97,9 @@ func Env() Environment {
|
||||||
|
|
||||||
// LocalEnv returns build environment metadata gathered from git.
|
// LocalEnv returns build environment metadata gathered from git.
|
||||||
func LocalEnv() Environment {
|
func LocalEnv() Environment {
|
||||||
env := applyEnvFlags(Environment{Name: "local", Repo: "ethereum/go-ethereum"})
|
env := applyEnvFlags(Environment{Name: "local", Repo: "cryptoecc/ETH-ECC"})
|
||||||
|
|
||||||
head := readGitFile("HEAD")
|
head := readGitFile("HEAD")
|
||||||
|
|
||||||
if fields := strings.Fields(head); len(fields) == 2 {
|
if fields := strings.Fields(head); len(fields) == 2 {
|
||||||
head = fields[1]
|
head = fields[1]
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -91,57 +91,36 @@ func (t *StateTrie) TryGet(key []byte) ([]byte, error) {
|
||||||
// If the specified account is not in the trie, nil will be returned.
|
// If the specified account is not in the trie, nil will be returned.
|
||||||
// If a trie node is not found in the database, a MissingNodeError is returned.
|
// If a trie node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) TryGetAccount(key []byte) (*types.StateAccount, error) {
|
func (t *StateTrie) TryGetAccount(key []byte) (*types.StateAccount, error) {
|
||||||
var ret types.StateAccount
|
|
||||||
res, err := t.trie.TryGet(t.hashKey(key))
|
res, err := t.trie.TryGet(t.hashKey(key))
|
||||||
if err != nil {
|
if res == nil || err != nil {
|
||||||
log.Error(fmt.Sprintf("Unhandled trie error: %v", err))
|
return nil, err
|
||||||
return &ret, err
|
|
||||||
}
|
}
|
||||||
if res == nil {
|
ret := new(types.StateAccount)
|
||||||
return nil, nil
|
err = rlp.DecodeBytes(res, ret)
|
||||||
}
|
return ret, err
|
||||||
err = rlp.DecodeBytes(res, &ret)
|
|
||||||
return &ret, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryGetAccountWithPreHashedKey does the same thing as TryGetAccount, however
|
// TryGetAccountWithPreHashedKey does the same thing as TryGetAccount, however
|
||||||
// it expects a key that is already hashed. This constitutes an abstraction leak,
|
// it expects a key that is already hashed. This constitutes an abstraction leak,
|
||||||
// since the client code needs to know the key format.
|
// since the client code needs to know the key format.
|
||||||
func (t *StateTrie) TryGetAccountWithPreHashedKey(key []byte) (*types.StateAccount, error) {
|
func (t *StateTrie) TryGetAccountWithPreHashedKey(key []byte) (*types.StateAccount, error) {
|
||||||
var ret types.StateAccount
|
|
||||||
res, err := t.trie.TryGet(key)
|
res, err := t.trie.TryGet(key)
|
||||||
if err != nil {
|
if res == nil || err != nil {
|
||||||
log.Error(fmt.Sprintf("Unhandled trie error: %v", err))
|
return nil, err
|
||||||
return &ret, err
|
|
||||||
}
|
}
|
||||||
if res == nil {
|
ret := new(types.StateAccount)
|
||||||
return nil, nil
|
err = rlp.DecodeBytes(res, ret)
|
||||||
}
|
return ret, err
|
||||||
err = rlp.DecodeBytes(res, &ret)
|
|
||||||
return &ret, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryGetNode attempts to retrieve a trie node by compact-encoded path. It is not
|
// TryGetNode attempts to retrieve a trie node by compact-encoded path. It is not
|
||||||
// possible to use keybyte-encoding as the path might contain odd nibbles.
|
// possible to use keybyte-encoding as the path might contain odd nibbles.
|
||||||
|
// If the specified trie node is not in the trie, nil will be returned.
|
||||||
|
// If a trie node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) TryGetNode(path []byte) ([]byte, int, error) {
|
func (t *StateTrie) TryGetNode(path []byte) ([]byte, int, error) {
|
||||||
return t.trie.TryGetNode(path)
|
return t.trie.TryGetNode(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryUpdateAccount account will abstract the write of an account to the
|
|
||||||
// secure trie.
|
|
||||||
func (t *StateTrie) TryUpdateAccount(key []byte, acc *types.StateAccount) error {
|
|
||||||
hk := t.hashKey(key)
|
|
||||||
data, err := rlp.EncodeToBytes(acc)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := t.trie.TryUpdate(hk, data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update associates key with value in the trie. Subsequent calls to
|
// Update associates key with value in the trie. Subsequent calls to
|
||||||
// Get will return value. If value has length zero, any existing value
|
// Get will return value. If value has length zero, any existing value
|
||||||
// is deleted from the trie and calls to Get will return nil.
|
// is deleted from the trie and calls to Get will return nil.
|
||||||
|
|
@ -161,7 +140,7 @@ func (t *StateTrie) Update(key, value []byte) {
|
||||||
// The value bytes must not be modified by the caller while they are
|
// The value bytes must not be modified by the caller while they are
|
||||||
// stored in the trie.
|
// stored in the trie.
|
||||||
//
|
//
|
||||||
// If a node was not found in the database, a MissingNodeError is returned.
|
// If a node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) TryUpdate(key, value []byte) error {
|
func (t *StateTrie) TryUpdate(key, value []byte) error {
|
||||||
hk := t.hashKey(key)
|
hk := t.hashKey(key)
|
||||||
err := t.trie.TryUpdate(hk, value)
|
err := t.trie.TryUpdate(hk, value)
|
||||||
|
|
@ -172,6 +151,21 @@ func (t *StateTrie) TryUpdate(key, value []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TryUpdateAccount account will abstract the write of an account to the
|
||||||
|
// secure trie.
|
||||||
|
func (t *StateTrie) TryUpdateAccount(key []byte, acc *types.StateAccount) error {
|
||||||
|
hk := t.hashKey(key)
|
||||||
|
data, err := rlp.EncodeToBytes(acc)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := t.trie.TryUpdate(hk, data); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Delete removes any existing value for key from the trie.
|
// Delete removes any existing value for key from the trie.
|
||||||
func (t *StateTrie) Delete(key []byte) {
|
func (t *StateTrie) Delete(key []byte) {
|
||||||
if err := t.TryDelete(key); err != nil {
|
if err := t.TryDelete(key); err != nil {
|
||||||
|
|
@ -180,14 +174,15 @@ func (t *StateTrie) Delete(key []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryDelete removes any existing value for key from the trie.
|
// TryDelete removes any existing value for key from the trie.
|
||||||
// If a node was not found in the database, a MissingNodeError is returned.
|
// If the specified trie node is not in the trie, nothing will be changed.
|
||||||
|
// If a node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) TryDelete(key []byte) error {
|
func (t *StateTrie) TryDelete(key []byte) error {
|
||||||
hk := t.hashKey(key)
|
hk := t.hashKey(key)
|
||||||
delete(t.getSecKeyCache(), string(hk))
|
delete(t.getSecKeyCache(), string(hk))
|
||||||
return t.trie.TryDelete(hk)
|
return t.trie.TryDelete(hk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryDeleteACcount abstracts an account deletion from the trie.
|
// TryDeleteAccount abstracts an account deletion from the trie.
|
||||||
func (t *StateTrie) TryDeleteAccount(key []byte) error {
|
func (t *StateTrie) TryDeleteAccount(key []byte) error {
|
||||||
hk := t.hashKey(key)
|
hk := t.hashKey(key)
|
||||||
delete(t.getSecKeyCache(), string(hk))
|
delete(t.getSecKeyCache(), string(hk))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue