fix config.go conflict

feature/dev-engine_test
static 12 months ago
commit 8fc39df5d9
  1. 3
      api/service/stagedstreamsync/staged_stream_sync.go
  2. 8
      api/service/stagedstreamsync/syncing.go
  3. 12
      consensus/consensus.go
  4. 7
      consensus/consensus_v2.go
  5. 2
      consensus/downloader.go
  6. 2
      consensus/validator.go
  7. 2
      core/blockchain_impl.go
  8. 3
      core/epochchain.go
  9. 2
      core/rawdb/accessors_offchain.go
  10. 4
      core/state/statedb.go
  11. 8
      internal/chain/engine.go
  12. 18
      internal/params/config.go
  13. 7
      node/node_handler.go
  14. 2
      node/node_syncing.go
  15. 31
      rpc/eth/types.go
  16. 12
      rpc/transaction.go
  17. 24
      staking/availability/measure.go
  18. 4
      test/build-localnet-validator.sh

@ -642,9 +642,10 @@ func (ss *StagedStreamSync) addConsensusLastMile(bc core.BlockChain, cs *consens
case errors.Is(err, core.ErrNotLastBlockInEpoch):
case err != nil:
return errors.Wrap(err, "failed to InsertChain")
}
default:
hashes = append(hashes, block.Header().Hash())
}
}
return nil
})
return hashes, err

@ -219,6 +219,8 @@ func (s *StagedStreamSync) Debug(source string, msg interface{}) {
// For each iteration, estimate the current block number, then fetch block & insert to blockchain
func (s *StagedStreamSync) doSync(downloaderContext context.Context, initSync bool) (uint64, int, error) {
startedNumber := s.bc.CurrentBlock().NumberU64()
var totalInserted int
s.initSync = initSync
@ -249,7 +251,7 @@ func (s *StagedStreamSync) doSync(downloaderContext context.Context, initSync bo
for {
ctx, cancel := context.WithCancel(downloaderContext)
n, err := s.doSyncCycle(ctx, initSync)
n, err := s.doSyncCycle(ctx)
if err != nil {
utils.Logger().Error().
Err(err).
@ -281,6 +283,8 @@ func (s *StagedStreamSync) doSync(downloaderContext context.Context, initSync bo
Bool("isBeacon", s.isBeacon).
Uint32("shard", s.bc.ShardID()).
Int("blocks", totalInserted).
Uint64("startedNumber", startedNumber).
Uint64("currentNumber", s.bc.CurrentBlock().NumberU64()).
Msg(WrapStagedSyncMsg("sync cycle blocks inserted successfully"))
}
@ -304,7 +308,7 @@ func (s *StagedStreamSync) doSync(downloaderContext context.Context, initSync bo
return estimatedHeight, totalInserted, nil
}
func (s *StagedStreamSync) doSyncCycle(ctx context.Context, initSync bool) (int, error) {
func (s *StagedStreamSync) doSyncCycle(ctx context.Context) (int, error) {
// TODO: initSync=true means currentCycleNumber==0, so we can remove initSync

@ -40,6 +40,10 @@ const (
AsyncProposal
)
type DownloadAsync interface {
DownloadAsync()
}
// Consensus is the main struct with all states and data related to consensus process.
type Consensus struct {
Decider quorum.Decider
@ -122,9 +126,7 @@ type Consensus struct {
// finalityCounter keep tracks of the finality time
finalityCounter atomic.Value //int64
dHelper interface {
DownloadAsync()
}
dHelper DownloadAsync
// Both flags only for initialization state.
start bool
@ -190,10 +192,10 @@ func (consensus *Consensus) BlocksSynchronized() {
}
// BlocksNotSynchronized lets the main loop know that block is not synchronized
func (consensus *Consensus) BlocksNotSynchronized() {
func (consensus *Consensus) BlocksNotSynchronized(reason string) {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.syncNotReadyChan()
consensus.syncNotReadyChan(reason)
}
// VdfSeedSize returns the number of VRFs for VDF computation

@ -359,11 +359,12 @@ func (consensus *Consensus) syncReadyChan() {
}
}
func (consensus *Consensus) syncNotReadyChan() {
consensus.getLogger().Info().Msg("[ConsensusMainLoop] syncNotReadyChan")
func (consensus *Consensus) syncNotReadyChan(reason string) {
mode := consensus.current.Mode()
consensus.setBlockNum(consensus.Blockchain().CurrentHeader().Number().Uint64() + 1)
consensus.current.SetMode(Syncing)
consensus.getLogger().Info().Msg("[ConsensusMainLoop] Node is OUT OF SYNC")
consensus.getLogger().Info().Msgf("[ConsensusMainLoop] syncNotReadyChan, prev %s, reason %s", mode.String(), reason)
consensus.getLogger().Info().Msgf("[ConsensusMainLoop] Node is OUT OF SYNC, reason: %s", reason)
consensusSyncCounterVec.With(prometheus.Labels{"consensus": "out_of_sync"}).Inc()
}

@ -61,7 +61,7 @@ func (dh *downloadHelper) downloadStartedLoop(c *Consensus) {
for {
select {
case <-dh.startedCh:
c.BlocksNotSynchronized()
c.BlocksNotSynchronized("downloadStartedLoop")
case err := <-dh.startedSub.Err():
c.GetLogger().Info().Err(err).Msg("consensus download finished loop closed")

@ -65,7 +65,7 @@ func (consensus *Consensus) onAnnounce(msg *msg_pb.Message) {
_, err := consensus.ValidateNewBlock(recvMsg)
if err == nil {
consensus.GetLogger().Info().
Msg("[Announce] Block verified")
Msgf("[Announce] Block verified %d", recvMsg.BlockNum)
}
}()
}

@ -1609,7 +1609,7 @@ func (bc *BlockChainImpl) insertChain(chain types.Blocks, verifyHeaders bool) (i
switch status {
case CanonStatTy:
logger.Info().Msg("Inserted new block")
logger.Info().Msgf("Inserted new block s: %d e: %d n:%d", block.ShardID(), block.Epoch().Uint64(), block.NumberU64())
coalescedLogs = append(coalescedLogs, logs...)
blockInsertTimer.UpdateSince(bstart)
events = append(events, ChainEvent{block, block.Hash(), logs})

@ -166,7 +166,8 @@ func (bc *EpochChain) InsertChain(blocks types.Blocks, _ bool) (int, error) {
se1()
se2()
utils.Logger().Info().
Msgf("[EPOCHSYNC] Added block %d %s", block.NumberU64(), block.Hash().Hex())
Msgf("[EPOCHSYNC] Added block %d, epoch %d, %s", block.NumberU64(), block.Epoch().Uint64(), block.Hash().Hex())
}
return 0, nil
}

@ -43,7 +43,7 @@ func WriteShardStateBytes(db DatabaseWriter, epoch *big.Int, data []byte) error
}
utils.Logger().Info().
Str("epoch", epoch.String()).
Int("size", len(data)).Msg("wrote sharding state")
Int("size", len(data)).Msgf("wrote sharding state, epoch %d", epoch.Uint64())
return nil
}

@ -895,7 +895,9 @@ func (db *DB) Finalise(deleteEmptyObjects bool) {
// Commit validator changes in cache to stateObjects
// TODO: remove validator cache after commit
for addr, wrapper := range db.stateValidators {
db.UpdateValidatorWrapper(addr, wrapper)
if err := db.UpdateValidatorWrapper(addr, wrapper); err != nil {
utils.Logger().Warn().Err(err).Msg("Unable to update the validator wrapper on the finalize")
}
}
addressesToPrefetch := make([][]byte, 0, len(db.journal.dirties))
for addr := range db.journal.dirties {

@ -555,6 +555,14 @@ func setElectionEpochAndMinFee(chain engine.ChainReader, header *block.Header, s
}
isElected[addr] = struct{}{}
}
if config.IsMaxRate(newShardState.Epoch) {
for _, addr := range chain.ValidatorCandidates() {
if _, err := availability.UpdateMaxCommissionFee(state, addr, minRate); err != nil {
return err
}
}
}
// due to a bug in the old implementation of the minimum fee,
// unelected validators did not have their fee updated even
// when the protocol required them to do so. here we fix it,

@ -76,6 +76,7 @@ var (
HIP30Epoch: big.NewInt(1673), // 2023-11-02 17:30:00+00:00
NoNilDelegationsEpoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(1673), // 2023-11-02 17:30:00+00:00
MaxRateEpoch: EpochTBD,
}
// TestnetChainConfig contains the chain parameters to run a node on the harmony test network.
@ -120,7 +121,7 @@ var (
HIP30Epoch: big.NewInt(2176), // 2023-10-12 10:00:00+00:00
NoNilDelegationsEpoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(2176), // 2023-10-12 10:00:00+00:00
MaxRateEpoch: EpochTBD,
}
// PangaeaChainConfig contains the chain parameters for the Pangaea network.
// All features except for CrossLink are enabled at launch.
@ -165,6 +166,7 @@ var (
HIP30Epoch: EpochTBD,
NoNilDelegationsEpoch: EpochTBD,
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
}
// PartnerChainConfig contains the chain parameters for the Partner network.
@ -203,13 +205,14 @@ var (
SlotsLimitedEpoch: EpochTBD, // epoch to enable HIP-16
CrossShardXferPrecompileEpoch: big.NewInt(5),
AllowlistEpoch: EpochTBD,
LeaderRotationInternalValidatorsEpoch: EpochTBD,
LeaderRotationInternalValidatorsEpoch: big.NewInt(2379),
LeaderRotationExternalValidatorsEpoch: EpochTBD,
FeeCollectEpoch: big.NewInt(5),
ValidatorCodeFixEpoch: big.NewInt(5),
HIP30Epoch: big.NewInt(7),
BlockGas30MEpoch: big.NewInt(7),
NoNilDelegationsEpoch: EpochTBD,
MaxRateEpoch: EpochTBD,
}
// StressnetChainConfig contains the chain parameters for the Stress test network.
@ -255,6 +258,7 @@ var (
HIP30Epoch: EpochTBD,
NoNilDelegationsEpoch: big.NewInt(2),
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
}
// LocalnetChainConfig contains the chain parameters to run for local development.
@ -299,6 +303,7 @@ var (
HIP30Epoch: EpochTBD,
NoNilDelegationsEpoch: big.NewInt(2),
BlockGas30MEpoch: big.NewInt(0),
MaxRateEpoch: EpochTBD,
}
// AllProtocolChanges ...
@ -345,6 +350,7 @@ var (
big.NewInt(0), // BlockGas30M
big.NewInt(0), // HIP30Epoch
big.NewInt(0), // NoNilDelegationsEpoch
big.NewInt(0), // MaxRateEpoch
}
// TestChainConfig ...
@ -391,6 +397,7 @@ var (
big.NewInt(0), // HIP30Epoch
big.NewInt(0), // NoNilDelegationsEpoch
big.NewInt(0), // BlockGas30M
big.NewInt(0), // MaxRateEpoch
}
// TestRules ...
@ -559,6 +566,9 @@ type ChainConfig struct {
HIP30Epoch *big.Int `json:"hip30-epoch,omitempty"`
BlockGas30MEpoch *big.Int `json:"block-gas-30m-epoch,omitempty"`
// MaxRateEpoch will make sure the validator max-rate is at least equal to the minRate + the validator max-rate-increase
MaxRateEpoch *big.Int `json:"max-rate-epoch,omitempty"`
}
// String implements the fmt.Stringer interface.
@ -834,6 +844,10 @@ func (c *ChainConfig) IsHIP30(epoch *big.Int) bool {
return isForked(c.HIP30Epoch, epoch)
}
func (c *ChainConfig) IsMaxRate(epoch *big.Int) bool {
return isForked(c.MaxRateEpoch, epoch)
}
// During this epoch, shards 2 and 3 will start sending
// their balances over to shard 0 or 1.
func (c *ChainConfig) IsOneEpochBeforeHIP30(epoch *big.Int) bool {

@ -337,7 +337,7 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) error {
}
BroadcastCXReceipts(newBlock, node.Consensus)
} else {
if node.Consensus.Mode() != consensus.Listening {
if mode := node.Consensus.Mode(); mode != consensus.Listening {
numSignatures := node.Consensus.NumSignaturesIncludedInBlock(newBlock)
utils.Logger().Info().
Uint64("blockNum", newBlock.NumberU64()).
@ -347,9 +347,12 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) error {
Int("numTxns", len(newBlock.Transactions())).
Int("numStakingTxns", len(newBlock.StakingTransactions())).
Uint32("numSignatures", numSignatures).
Str("mode", mode.String()).
Msg("BINGO !!! Reached Consensus")
if node.Consensus.Mode() == consensus.Syncing {
node.Consensus.SetMode(node.Consensus.UpdateConsensusInformation())
mode = node.Consensus.UpdateConsensusInformation()
utils.Logger().Info().Msgf("Switching to mode %s", mode)
node.Consensus.SetMode(mode)
}
node.Consensus.UpdateValidatorMetrics(float64(numSignatures), float64(newBlock.NumberU64()))

@ -316,7 +316,7 @@ func (node *Node) doSync(syncInstance ISync, syncingPeerProvider SyncingPeerProv
if isSynchronized, _, _ := syncInstance.GetParsedSyncStatusDoubleChecked(); !isSynchronized {
node.IsSynchronized.UnSet()
if willJoinConsensus {
consensus.BlocksNotSynchronized()
consensus.BlocksNotSynchronized("node.doSync")
}
isBeacon := bc.ShardID() == shard.BeaconChainShardID
syncInstance.SyncLoop(bc, isBeacon, consensus, legacysync.LoopMinTime)

@ -110,6 +110,37 @@ func NewTransaction(
}
return result, nil
}
func NewTransactionFromTransaction(
tx *types.Transaction, blockHash common.Hash,
blockNumber uint64, timestamp uint64, index uint64,
) (*Transaction, error) {
from, err := tx.SenderAddress()
if err != nil {
return nil, fmt.Errorf("unable to get sender address: %w", err)
}
v, r, s := tx.RawSignatureValues()
result := &Transaction{
From: from,
Gas: hexutil.Uint64(tx.GasLimit()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
Hash: tx.Hash(),
Input: hexutil.Bytes(tx.Data()),
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
Value: (*hexutil.Big)(tx.Value()),
Timestamp: hexutil.Uint64(timestamp),
V: (*hexutil.Big)(v),
R: (*hexutil.Big)(r),
S: (*hexutil.Big)(s),
}
if blockHash != (common.Hash{}) {
result.BlockHash = &blockHash
result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber))
result.TransactionIndex = (*hexutil.Uint64)(&index)
}
return result, nil
}
// NewReceipt returns the RPC data for a new receipt
func NewReceipt(tx *types.EthTransaction, blockHash common.Hash, blockNumber, blockIndex uint64, receipt *types.Receipt) (map[string]interface{}, error) {

@ -236,7 +236,7 @@ func (s *PublicTransactionService) newRPCTransaction(tx *types.Transaction, bloc
}
return NewStructuredResponse(tx)
case Eth:
tx, err := eth.NewTransaction(tx.ConvertToEth(), blockHash, blockNumber, timestamp, index)
tx, err := eth.NewTransactionFromTransaction(tx, blockHash, blockNumber, timestamp, index)
if err != nil {
DoMetricRPCQueryInfo(GetTransactionByHash, FailedNumber)
return nil, err
@ -751,7 +751,7 @@ func (s *PublicTransactionService) GetTransactionReceipt(
return nil, err
}
return NewStructuredResponse(RPCReceipt)
case V2:
case V2, Eth:
if tx == nil {
RPCReceipt, err = v2.NewReceipt(stx, blockHash, blockNumber, index, receipt)
} else {
@ -761,14 +761,6 @@ func (s *PublicTransactionService) GetTransactionReceipt(
return nil, err
}
return NewStructuredResponse(RPCReceipt)
case Eth:
if tx != nil {
RPCReceipt, err = eth.NewReceipt(tx.ConvertToEth(), blockHash, blockNumber, index, receipt)
}
if err != nil {
return nil, err
}
return NewStructuredResponse(RPCReceipt)
default:
return nil, ErrUnknownRPCVersion
}

@ -267,3 +267,27 @@ func UpdateMinimumCommissionFee(
}
return false, nil
}
// UpdateMaxCommissionFee makes sure the max-rate is at least higher than the rate + max-rate-change.
func UpdateMaxCommissionFee(state *state.DB, addr common.Address, minRate numeric.Dec) (bool, error) {
utils.Logger().Info().Msg("begin update max commission fee")
wrapper, err := state.ValidatorWrapper(addr, true, false)
if err != nil {
return false, err
}
minMaxRate := minRate.Add(wrapper.MaxChangeRate)
if wrapper.MaxRate.LT(minMaxRate) {
utils.Logger().Info().
Str("addr", addr.Hex()).
Str("old max-rate", wrapper.MaxRate.String()).
Str("new max-rate", minMaxRate.String()).
Msg("updating max commission rate")
wrapper.MaxRate.SetBytes(minMaxRate.Bytes())
return true, nil
}
return false, nil
}

@ -32,7 +32,7 @@ hmy --node="http://localhost:9500" staking create-validator \
--bls-pubkeys 4f41a37a3a8d0695dd6edcc58142c6b7d98e74da5c90e79b587b3b960b6a4f5e048e6d8b8a000d77a478d44cd640270c,7dcc035a943e29e17959dabe636efad7303d2c6f273ace457ba9dcc2fd19d3f37e70ba1cd8d082cf8ff7be2f861db48c \
--name "s0-localnet-validator1" --identity "validator1" --details "validator1" \
--security-contact "localnet" --website "localnet.one" \
--max-change-rate 0.1 --max-rate 0.1 --rate 0.1 \
--max-change-rate 0.01 --max-rate 0.01 --rate 0.01 \
--max-total-delegation 100000000 --min-self-delegation 10000 --bls-pubkeys-dir .hmy/extbls/
hmy --node="http://localhost:9500" staking create-validator \
@ -40,7 +40,7 @@ hmy --node="http://localhost:9500" staking create-validator \
--bls-pubkeys b0917378b179a519a5055259c4f8980cce37d58af300b00dd98b07076d3d9a3b16c4a55f84522f553872225a7b1efc0c \
--name "s0-localnet-validator2" --identity "validator2" --details "validator2" \
--security-contact "localnet" --website "localnet.one" \
--max-change-rate 0.1 --max-rate 0.1 --rate 0.1 \
--max-change-rate 0.1 --max-rate 0.1 --rate 0.05 \
--max-total-delegation 100000000 --min-self-delegation 10000 --bls-pubkeys-dir .hmy/extbls/
hmy --node="http://localhost:9500" staking create-validator \

Loading…
Cancel
Save