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

added GetTotalAccounts & GetTotalValidators into GetBlockchainInfo. #439

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/gtk/startup_assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ Now you are ready to start the node!`
}
assistant.SetPageComplete(pageSeed, true)
}
case pageSeedConfirmName:
{
}
// case pageSeedConfirmName:
// {
// }
case pagePasswordName:
{
assistant.SetPageComplete(pagePassword, true)
Expand Down
10 changes: 5 additions & 5 deletions committee/committee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

func copyValidator(val *validator.Validator) *validator.Validator {
copy := validator.NewValidator(val.PublicKey(), val.Number())
copy.UpdateLastBondingHeight(val.LastBondingHeight())
copy.UpdateLastJoinedHeight(val.LastJoinedHeight())
copy.UpdateUnbondingHeight(val.UnbondingHeight())
clone := validator.NewValidator(val.PublicKey(), val.Number())
clone.UpdateLastBondingHeight(val.LastBondingHeight())
clone.UpdateLastJoinedHeight(val.LastJoinedHeight())
clone.UpdateUnbondingHeight(val.UnbondingHeight())

// Stake can't be changes as long as validator is inside committee
// Check Bond executor
return copy
return clone
}
func TestContains(t *testing.T) {
committee, signers := GenerateTestCommittee(21)
Expand Down
4 changes: 2 additions & 2 deletions consensus/change_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func (s *changeProposerState) onAddVote(v *vote.Vote) {
}
}

func (s *changeProposerState) onSetProposal(p *proposal.Proposal) {
func (s *changeProposerState) onSetProposal(_ *proposal.Proposal) {
// Ignore proposals
}

func (s *changeProposerState) onTimeout(t *ticker) {
func (s *changeProposerState) onTimeout(_ *ticker) {
// Ignore timeouts
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *commitState) onSetProposal(p *proposal.Proposal) {
s.decide()
}

func (s *commitState) onTimeout(t *ticker) {
func (s *commitState) onTimeout(_ *ticker) {
// Ignore timeouts
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/height.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *newHeightState) onAddVote(v *vote.Vote) {
s.doAddVote(v)
}

func (s *newHeightState) onSetProposal(p *proposal.Proposal) {
func (s *newHeightState) onSetProposal(_ *proposal.Proposal) {
}

func (s *newHeightState) onTimeout(t *ticker) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/precommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *precommitState) onSetProposal(p *proposal.Proposal) {
}
}

func (s *precommitState) onTimeout(t *ticker) {
func (s *precommitState) onTimeout(_ *ticker) {
// Ignore timeouts
}

Expand Down
6 changes: 3 additions & 3 deletions consensus/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func (s *proposeState) createProposal(height uint32, round int16) {
s.broadcastProposal(proposal)
}

func (s *proposeState) onAddVote(v *vote.Vote) {
func (s *proposeState) onAddVote(_ *vote.Vote) {
panic("Unreachable")
}

func (s *proposeState) onSetProposal(p *proposal.Proposal) {
func (s *proposeState) onSetProposal(_ *proposal.Proposal) {
panic("Unreachable")
}

func (s *proposeState) onTimeout(t *ticker) {
func (s *proposeState) onTimeout(_ *ticker) {
panic("Unreachable")
}
func (s *proposeState) name() string {
Expand Down
2 changes: 1 addition & 1 deletion network/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (mock *MockNetwork) SendTo(data []byte, pid lp2pcore.PeerID) error {
}
return nil
}
func (mock *MockNetwork) Broadcast(data []byte, tid TopicID) error {
func (mock *MockNetwork) Broadcast(data []byte, _ TopicID) error {
mock.BroadcastCh <- BroadcastData{
Data: data,
Target: nil, // Send to all
Expand Down
12 changes: 6 additions & 6 deletions sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func (sb *sandbox) Account(addr crypto.Address) *account.Account {

s, ok := sb.accounts[addr]
if ok {
copy := new(account.Account)
*copy = s.Account
return copy
clone := new(account.Account)
*clone = s.Account
return clone
}

acc, err := sb.store.Account(addr)
Expand Down Expand Up @@ -130,9 +130,9 @@ func (sb *sandbox) Validator(addr crypto.Address) *validator.Validator {

s, ok := sb.validators[addr]
if ok {
copy := new(validator.Validator)
*copy = s.Validator
return copy
clone := new(validator.Validator)
*clone = s.Validator
return clone
}

val, err := sb.store.Validator(addr)
Expand Down
2 changes: 2 additions & 0 deletions state/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Facade interface {
IsProposer(addr crypto.Address, round int16) bool
IsValidator(addr crypto.Address) bool
TotalPower() int64
TotalAccounts() int32
TotalValidators() int32
CommitteePower() int64
PendingTx(id tx.ID) *tx.Tx
AddPendingTx(trx *tx.Tx) error
Expand Down
13 changes: 11 additions & 2 deletions state/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func (m *MockState) CommitBlock(h uint32, b *block.Block, cert *block.Certificat
func (m *MockState) Close() error {
return nil
}
func (m *MockState) ProposeBlock(round int16) (*block.Block, error) {
func (m *MockState) ProposeBlock(_ int16) (*block.Block, error) {
b := block.GenerateTestBlock(nil, nil)
return b, nil
}
func (m *MockState) ValidateBlock(block *block.Block) error {
func (m *MockState) ValidateBlock(_ *block.Block) error {
return nil
}
func (m *MockState) CommitteeValidators() []*validator.Validator {
Expand All @@ -122,6 +122,15 @@ func (m *MockState) IsProposer(addr crypto.Address, round int16) bool {
func (m *MockState) IsValidator(addr crypto.Address) bool {
return m.TestStore.HasValidator(addr)
}

func (m *MockState) TotalValidators() int32 {
return m.TestStore.TotalAccounts()
}

func (m *MockState) TotalAccounts() int32 {
return m.TestStore.TotalAccounts()
}

func (m *MockState) TotalPower() int64 {
p := int64(0)
m.TestStore.IterateValidators(func(val *validator.Validator) bool {
Expand Down
14 changes: 9 additions & 5 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,7 @@ func (st *state) ValidateBlock(block *block.Block) error {
}

sb := st.concreteSandbox()
if err := st.executeBlock(block, sb); err != nil {
return err
}

return nil
return st.executeBlock(block, sb)
}

func (st *state) CommitBlock(height uint32, block *block.Block, cert *block.Certificate) error {
Expand Down Expand Up @@ -596,6 +592,14 @@ func (st *state) CommitteeValidators() []*validator.Validator {
return st.committee.Validators()
}

func (st *state) TotalAccounts() int32 {
return st.store.TotalAccounts()
}

func (st *state) TotalValidators() int32 {
return st.store.TotalValidators()
}

func (st *state) IsInCommittee(addr crypto.Address) bool {
return st.committee.Contains(addr)
}
Expand Down
6 changes: 1 addition & 5 deletions sync/bundle/message/block_announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ func (m *BlockAnnounceMessage) SanityCheck() error {
if err := m.Block.SanityCheck(); err != nil {
return err
}
if err := m.Certificate.SanityCheck(); err != nil {
return err
}

return nil
return m.Certificate.SanityCheck()
}

func (m *BlockAnnounceMessage) Type() Type {
Expand Down
5 changes: 1 addition & 4 deletions sync/bundle/message/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ func (m *HelloMessage) SanityCheck() error {
if m.PublicKey == nil {
return errors.Error(errors.ErrInvalidPublicKey)
}
if err := m.PublicKey.Verify(m.SignBytes(), m.Signature); err != nil {
return err
}
return nil
return m.PublicKey.Verify(m.SignBytes(), m.Signature)
}

func (m *HelloMessage) SignBytes() []byte {
Expand Down
6 changes: 1 addition & 5 deletions sync/bundle/message/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ func NewProposalMessage(p *proposal.Proposal) *ProposalMessage {
}

func (m *ProposalMessage) SanityCheck() error {
if err := m.Proposal.SanityCheck(); err != nil {
return err
}

return nil
return m.Proposal.SanityCheck()
}

func (m *ProposalMessage) Type() Type {
Expand Down
5 changes: 1 addition & 4 deletions sync/bundle/message/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ func NewVoteMessage(v *vote.Vote) *VoteMessage {
}

func (m *VoteMessage) SanityCheck() error {
if err := m.Vote.SanityCheck(); err != nil {
return err
}
return nil
return m.Vote.SanityCheck()
}

func (m *VoteMessage) Type() Type {
Expand Down
2 changes: 1 addition & 1 deletion sync/handler_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newProposalHandler(sync *synchronizer) messageHandler {
}
}

func (handler *proposalHandler) ParsMessage(m message.Message, initiator peer.ID) error {
func (handler *proposalHandler) ParsMessage(m message.Message, _ peer.ID) error {
msg := m.(*message.ProposalMessage)
handler.logger.Trace("parsing Proposal message", "message", msg)

Expand Down
2 changes: 1 addition & 1 deletion sync/handler_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newTransactionsHandler(sync *synchronizer) messageHandler {
}
}

func (handler *transactionsHandler) ParsMessage(m message.Message, initiator peer.ID) error {
func (handler *transactionsHandler) ParsMessage(m message.Message, _ peer.ID) error {
msg := m.(*message.TransactionsMessage)
handler.logger.Trace("parsing Transactions message", "message", msg)

Expand Down
2 changes: 1 addition & 1 deletion sync/handler_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func newVoteHandler(sync *synchronizer) messageHandler {
}
}

func (handler *voteHandler) ParsMessage(m message.Message, initiator peer.ID) error {
func (handler *voteHandler) ParsMessage(m message.Message, _ peer.ID) error {
msg := m.(*message.VoteMessage)
handler.logger.Trace("parsing Vote message", "message", msg)

Expand Down
4 changes: 2 additions & 2 deletions txpool/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func MockingTxPool() *MockTxPool {
Txs: make([]*tx.Tx, 0),
}
}
func (m *MockTxPool) SetNewSandboxAndRecheck(sb sandbox.Sandbox) {}
func (m *MockTxPool) SetNewSandboxAndRecheck(_ sandbox.Sandbox) {}
func (m *MockTxPool) PendingTx(id tx.ID) *tx.Tx {
for _, t := range m.Txs {
if t.ID().EqualsTo(id) {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (m *MockTxPool) AppendTxAndBroadcast(trx *tx.Tx) error {
return nil
}

func (m *MockTxPool) RemoveTx(id hash.Hash) {
func (m *MockTxPool) RemoveTx(_ hash.Hash) {
// This test pools is shared between different test objects
//delete(m.Txs, id)
}
Expand Down
6 changes: 3 additions & 3 deletions types/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ func (b *Block) Decode(r io.Reader) error {
return err
}
}
len, err := encoding.ReadVarInt(r)
length, err := encoding.ReadVarInt(r)
if err != nil {
return err
}
b.data.Txs = make([]*tx.Tx, len)
for i := 0; i < int(len); i++ {
b.data.Txs = make([]*tx.Tx, length)
for i := 0; i < int(length); i++ {
tx := new(tx.Tx)
if err := tx.Decode(r); err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions types/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ func TestCBORMarshaling(t *testing.T) {

func TestEncodingBlock(t *testing.T) {
blk := GenerateTestBlock(nil, nil)
len := blk.SerializeSize()
length := blk.SerializeSize()

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
w := util.NewFixedWriter(i)
assert.Error(t, blk.Encode(w), "encode test %v failed", i)
}
w := util.NewFixedWriter(len)
w := util.NewFixedWriter(length)
assert.NoError(t, blk.Encode(w))

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
blk2 := new(Block)
r := util.NewFixedReader(i, w.Bytes())
assert.Error(t, blk2.Decode(r), "decode test %v failed", i)
}

blk2 := new(Block)
r := util.NewFixedReader(len, w.Bytes())
r := util.NewFixedReader(length, w.Bytes())
assert.NoError(t, blk2.Decode(r))
assert.Equal(t, blk.Hash(), blk2.Hash())
assert.Equal(t, blk.Header(), blk2.Header())
Expand Down
5 changes: 1 addition & 4 deletions types/block/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ func (cert *Certificate) Encode(w io.Writer) error {
return err
}
}
if err := cert.data.Signature.Encode(w); err != nil {
return err
}

return nil
return cert.data.Signature.Encode(w)
}

func (cert *Certificate) Decode(r io.Reader) error {
Expand Down
6 changes: 1 addition & 5 deletions types/tx/payload/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ func (p *SendPayload) SanityCheck() error {
if err := p.Sender.SanityCheck(); err != nil {
return err
}
if err := p.Receiver.SanityCheck(); err != nil {
return err
}

return nil
return p.Receiver.SanityCheck()
}

func (p *SendPayload) SerializeSize() int {
Expand Down
10 changes: 5 additions & 5 deletions types/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ func TestCBORMarshaling(t *testing.T) {

func TestEncodingTx(t *testing.T) {
tx1, _ := GenerateTestSendTx()
len := tx1.SerializeSize()
length := tx1.SerializeSize()

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
w := util.NewFixedWriter(i)
assert.Error(t, tx1.Encode(w), "encode test %v failed", i)
}
w := util.NewFixedWriter(len)
w := util.NewFixedWriter(length)
assert.NoError(t, tx1.Encode(w))

for i := 0; i < len; i++ {
for i := 0; i < length; i++ {
tx2 := new(Tx)
r := util.NewFixedReader(i, w.Bytes())
assert.Error(t, tx2.Decode(r), "decode test %v failed", i)
}

tx2 := new(Tx)
r := util.NewFixedReader(len, w.Bytes())
r := util.NewFixedReader(length, w.Bytes())
assert.NoError(t, tx2.Decode(r))
assert.Equal(t, tx1.ID(), tx2.ID())
}
Expand Down