From 4332456eed1ea46a66a0f260f865c00eda80d8ba Mon Sep 17 00:00:00 2001 From: mantre Date: Sat, 29 Jul 2023 13:07:25 +0800 Subject: [PATCH] fix: fixing review comments --- committee/committee.go | 2 -- execution/executor/sortition.go | 2 +- types/account/account.go | 2 -- www/http/blockchain.go | 10 +--------- www/http/validator.go | 19 +++++-------------- 5 files changed, 7 insertions(+), 28 deletions(-) diff --git a/committee/committee.go b/committee/committee.go index 6129fcc11..e0e57a123 100644 --- a/committee/committee.go +++ b/committee/committee.go @@ -69,8 +69,6 @@ func (c *committee) Update(lastRound int16, joined []*validator.Validator) { } else { committeeVal.UpdateLastSortitionHeight(val.LastSortitionHeight()) - // TODO: PRoofread the comments here - // // Ensure that a validator's stake and bonding properties // remain unchanged while they are part of the committee. // Refer to the Bond executor for additional details. diff --git a/execution/executor/sortition.go b/execution/executor/sortition.go index 83e2ed331..3137e206e 100644 --- a/execution/executor/sortition.go +++ b/execution/executor/sortition.go @@ -44,7 +44,7 @@ func (e *SortitionExecutor) Execute(trx *tx.Tx, sb sandbox.Sandbox) error { return errors.Errorf(errors.ErrInvalidSequence, "expected: %v, got: %v", val.Sequence()+1, trx.Sequence()) } - // Check for the duplicated sortition transactions + // Check for the duplicated or expired sortition transactions if sortitionHeight <= val.LastSortitionHeight() { return errors.Errorf(errors.ErrInvalidTx, "duplicated sortition transaction") diff --git a/types/account/account.go b/types/account/account.go index 173615b60..660e0a938 100644 --- a/types/account/account.go +++ b/types/account/account.go @@ -70,13 +70,11 @@ func (acc *Account) AddToBalance(amt int64) { acc.data.Balance += amt } -// IncSequence increments the account's sequence every time it signs a transaction. // IncSequence increases the sequence anytime this account signs a transaction. func (acc *Account) IncSequence() { acc.data.Sequence++ } -// Hash returns the hash of this account. // Hash calculates and returns the hash of the account. func (acc *Account) Hash() hash.Hash { bs, err := acc.Bytes() diff --git a/www/http/blockchain.go b/www/http/blockchain.go index bb167ce8f..b68a5b940 100644 --- a/www/http/blockchain.go +++ b/www/http/blockchain.go @@ -26,15 +26,7 @@ func (s *Server) BlockchainHandler(w http.ResponseWriter, _ *http.Request) { tm.addRowAmount("Committee Power", res.CommitteePower) for i, val := range res.CommitteeValidators { tm.addRowInt("--- Validator", i+1) - tm.addRowString("Public Key", val.PublicKey) - tm.addRowValAddress("Address", val.Address) - tm.addRowInt("Number", int(val.Number)) - tm.addRowInt("Sequence", int(val.Sequence)) - tm.addRowAmount("Stake", val.Stake) - tm.addRowInt("LastBondingHeight", int(val.LastBondingHeight)) - tm.addRowInt("LastSortitionHeight", int(val.LastSortitionHeight)) - tm.addRowInt("UnbondingHeight", int(val.UnbondingHeight)) - tm.addRowBytes("Hash", val.Hash) + s.writeValidatorTable(w, val) } s.writeHTML(w, tm.html()) diff --git a/www/http/validator.go b/www/http/validator.go index c9843e0d9..57af0ba30 100644 --- a/www/http/validator.go +++ b/www/http/validator.go @@ -18,19 +18,7 @@ func (s *Server) GetValidatorHandler(w http.ResponseWriter, r *http.Request) { return } - val := res.Validator - tm := newTableMaker() - tm.addRowString("Public Key", val.PublicKey) - tm.addRowValAddress("Address", val.Address) - tm.addRowInt("Number", int(val.Number)) - tm.addRowInt("Sequence", int(val.Sequence)) - tm.addRowAmount("Stake", val.Stake) - tm.addRowInt("LastBondingHeight", int(val.LastBondingHeight)) - tm.addRowInt("LastSortitionHeight", int(val.LastSortitionHeight)) - tm.addRowInt("UnbondingHeight", int(val.UnbondingHeight)) - tm.addRowBytes("Hash", val.Hash) - - s.writeHTML(w, tm.html()) + s.writeValidatorTable(w, res.Validator) } // GetValidatorByNumberHandler returns a handler to get validator by number. @@ -51,7 +39,10 @@ func (s *Server) GetValidatorByNumberHandler(w http.ResponseWriter, r *http.Requ return } - val := res.Validator + s.writeValidatorTable(w, res.Validator) +} + +func (s *Server) writeValidatorTable(w http.ResponseWriter, val *pactus.ValidatorInfo) { tm := newTableMaker() tm.addRowString("Public Key", val.PublicKey) tm.addRowValAddress("Address", val.Address)