[availabililty] Move when reset of counters occurs, more log on bumping sign counts, remove leftover test… (#2339)

* [availabililty] More log on bumping sign counts, remove leftover test script

* [availability] Move reset of counters after bumping counts & setting MIA validators as inactive

* [engine] Remove unnecessary guard on nil pointer of ValidatorWrapper
pull/2324/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent dcfffa8e49
commit efd6a47b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 81
      internal/chain/engine.go
  2. 24
      staking/availability/measure.go
  3. 63
      test/crt-validator.sh

@ -282,46 +282,18 @@ func (e *engineImpl) Finalize(
"[Finalize] failed to get validator from state to finalize",
).WithCause(err)
}
if wrapper != nil {
for i := range wrapper.Delegations {
delegation := &wrapper.Delegations[i]
totalWithdraw := delegation.RemoveUnlockedUndelegations(
header.Epoch(), wrapper.LastEpochInCommittee,
)
state.AddBalance(delegation.DelegatorAddress, totalWithdraw)
}
if err := state.UpdateValidatorWrapper(
validator, wrapper,
); err != nil {
return nil, nil, ctxerror.New("[Finalize] failed update validator info").WithCause(err)
}
for i := range wrapper.Delegations {
delegation := &wrapper.Delegations[i]
totalWithdraw := delegation.RemoveUnlockedUndelegations(
header.Epoch(), wrapper.LastEpochInCommittee,
)
state.AddBalance(delegation.DelegatorAddress, totalWithdraw)
}
}
newShardState, err := header.GetShardState()
if err != nil {
return nil, nil, ctxerror.New("[Finalize] failed to read shard state").WithCause(err)
}
if stkd := newShardState.StakedValidators(); stkd.CountStakedValidator > 0 {
for _, addr := range stkd.Addrs {
wrapper, err := state.ValidatorWrapper(addr)
if err != nil {
return nil, nil, err
}
// Set the LastEpochInCommittee field for all
// external validators in the upcoming epoch.
// and set the availability tracking counters to 0
wrapper.LastEpochInCommittee = newShardState.Epoch
wrapper.Counters.NumBlocksSigned.SetInt64(0)
wrapper.Counters.NumBlocksToSign.SetInt64(0)
if err := state.UpdateValidatorWrapper(addr, wrapper); err != nil {
return nil, nil, ctxerror.New(
"[Finalize] failed update validator info",
).WithCause(err)
}
if err := state.UpdateValidatorWrapper(
validator, wrapper,
); err != nil {
const msg = "[Finalize] failed update validator info"
return nil, nil, ctxerror.New(msg).WithCause(err)
}
}
}
@ -336,12 +308,10 @@ func (e *engineImpl) Finalize(
chain.CurrentHeader().Epoch(),
)
staked := superCommittee.StakedValidators()
// could happen that only harmony nodes are running,
// so just early return
if staked.CountStakedValidator > 0 {
l.RawJSON("external", []byte(staked.StateSubset.String())).
Msg("have non-zero external ")
Msg("have non-zero external")
if err != nil {
return nil, nil, err
@ -361,6 +331,33 @@ func (e *engineImpl) Finalize(
); err != nil {
return nil, nil, err
}
// Now can reset the counters, do note, only
// after the availability logic runs
newShardState, err := header.GetShardState()
if err != nil {
const msg = "[Finalize] failed to read shard state"
return nil, nil, ctxerror.New(msg).WithCause(err)
}
if stkd := newShardState.StakedValidators(); stkd.CountStakedValidator > 0 {
for _, addr := range stkd.Addrs {
wrapper, err := state.ValidatorWrapper(addr)
if err != nil {
return nil, nil, err
}
// Set the LastEpochInCommittee field for all
// external validators in the upcoming epoch.
// and set the availability tracking counters to 0
wrapper.LastEpochInCommittee = newShardState.Epoch
wrapper.Counters.NumBlocksSigned.SetInt64(0)
wrapper.Counters.NumBlocksToSign.SetInt64(0)
if err := state.UpdateValidatorWrapper(addr, wrapper); err != nil {
return nil, nil, ctxerror.New(
"[Finalize] failed update validator info",
).WithCause(err)
}
}
}
}
}
}

@ -116,9 +116,9 @@ func bumpCount(
didSign bool,
stakedAddrSet map[common.Address]struct{},
) error {
l := utils.Logger().Info()
for i := range signers {
addr := signers[i].EcdsaAddress
// NOTE if the signer address is not part of the staked addrs,
// then it must be a harmony operated node running,
// hence keep on going
@ -130,14 +130,23 @@ func bumpCount(
if err != nil {
return err
}
l.RawJSON("validator", []byte(wrapper.String())).
Msg("about to adjust counters")
wrapper.Counters.NumBlocksToSign.Add(
wrapper.Counters.NumBlocksToSign, common.Big1,
)
if didSign {
wrapper.Counters.NumBlocksSigned.Add(
wrapper.Counters.NumBlocksSigned, common.Big1,
)
}
l.RawJSON("validator", []byte(wrapper.String())).
Msg("bumped signing counters")
if err := state.UpdateValidatorWrapper(
addr, wrapper,
); err != nil {
@ -153,15 +162,18 @@ func IncrementValidatorSigningCounts(
shardID uint32, state *state.DB,
stakedAddrSet map[common.Address]struct{},
) error {
l := utils.Logger().Info().Str("candidate-header", header.String())
_, signers, missing, err := BallotResult(chain, header, shardID)
if err != nil {
return err
}
l.Msg("bumping signing counters for non-missing signers")
if err := bumpCount(
chain, state, signers, true, stakedAddrSet,
); err != nil {
return err
}
l.Msg("bumping missed signing counter ")
return bumpCount(chain, state, missing, false, stakedAddrSet)
}
@ -191,7 +203,7 @@ func SetInactiveUnavailableValidators(
return err
}
stats, snapEpoch, snapSigned, snapToSign :=
statsNow, snapEpoch, snapSigned, snapToSign :=
wrapper.Counters,
snapshot.LastEpochInCommittee,
snapshot.Counters.NumBlocksSigned,
@ -216,20 +228,20 @@ func SetInactiveUnavailableValidators(
}
signed, toSign :=
new(big.Int).Sub(stats.NumBlocksSigned, snapSigned),
new(big.Int).Sub(stats.NumBlocksToSign, snapToSign)
new(big.Int).Sub(statsNow.NumBlocksSigned, snapSigned),
new(big.Int).Sub(statsNow.NumBlocksToSign, snapToSign)
if signed.Sign() == -1 {
return errors.Wrapf(
errNegativeSign, "diff for signed period wrong: stat %s, snapshot %s",
stats.NumBlocksSigned.String(), snapSigned.String(),
statsNow.NumBlocksSigned.String(), snapSigned.String(),
)
}
if toSign.Sign() == -1 {
return errors.Wrapf(
errNegativeSign, "diff for toSign period wrong: stat %s, snapshot %s",
stats.NumBlocksToSign.String(), snapToSign.String(),
statsNow.NumBlocksToSign.String(), snapToSign.String(),
)
}

@ -1,63 +0,0 @@
#!/bin/bash
from='one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur'
to='one14438psd5vrjes7qm97jrj3t0s5l4qff5j5cn4h'
someRando='one1nqevvacj3y5ltuef05my4scwy5wuqteur72jk5'
endpt="http://34.230.39.233:9500"
amt="50"
export BLS_KEY='377c28caf0fd5ef5a914109c618245804b8c3336e131e4f9e4129fbed9a51ec6ba8ed89fffd1776ac530a2f50d888613'
export BLS_KEY_PATH='/home/edgar/go/src/github.com/harmony-one/harmony/377c28caf0fd5ef5a914109c618245804b8c3336e131e4f9e4129fbed9a51ec6ba8ed89fffd1776ac530a2f50d888613.key'
export BOOTNODE_PATH='/ip4/52.40.84.2/tcp/9876/p2p/QmbPVwrqWsTYXq1RxGWcxx9SWaTUCfoo1wA6wmdbduWe29'
set -eu
# transfer from already imported account (one of the ones that generates tokens)
printf 'Sent %s from funded account to external validator\n' $amt
hmy transfer --from "${from}" \
--from-shard 0 --to-shard 0 \
--to "${to}" --amount $amt \
--timeout 30 -n "${endpt}"
printf 'Sent %s from funded account to rando delegator\n' $amt
# transfer for our rando delegator
hmy transfer --from "${from}" \
--from-shard 0 --to-shard 0 \
--to "${someRando}" --amount 50 \
--timeout 30 --node "${endpt}"
printf 'Check balance of our addr for create-validator\n'
hmy balances "${to}" -n "${endpt}"
printf 'Create the actual validator\n'
hmy staking create-validator --validator-addr "${to}" \
--name _Test_key_validator0 --identity test_account \
--website harmony.one --security-contact Edgar-VDM \
--details none --rate 0.16798352018382678 \
--max-rate 0.1791844697821372 \
--max-change-rate 0.1522127615232536 \
--min-self-delegation 1.0 \
--max-total-delegation 13 \
--amount 6.6 \
--bls-pubkeys "${BLS_KEY}" \
--chain-id testnet --timeout 30 \
--node "${endpt}" || true
printf 'Wait 10 seconds, then delegation from our rando addr to our created-validator\n'
# Need to do a delegator test
sleep 10
hmy staking delegate \
--delegator-addr "${someRando}" --validator-addr "${to}" \
--amount 1.5 --timeout 30 -n "${endpt}" || true
cp scripts/node.sh bin
cd bin
touch blspass
sudo ./node.sh -p blspass -N slashing -z -D
Loading…
Cancel
Save