Skip to content

Commit

Permalink
Merge branch 'feature/bump-version-to-1.5.1' of https://github.com/Pl…
Browse files Browse the repository at this point in the history
…atONnetwork/PlatON-Go into feature/bump-version-to-1.5.1

# Conflicts:
#	consensus/cbft/cbft_test_util.go
  • Loading branch information
cheng762 committed Nov 29, 2023
2 parents e03267c + c3ff082 commit 3b97004
Show file tree
Hide file tree
Showing 74 changed files with 353 additions and 702 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ run:
skip-dirs-use-default: true
skip-files:
- core/genesis_alloc.go
- log/term/terminal_notwindows.go
skip-dirs:
- common/math
- common/json
- common/sort

linters:
disable-all: true
Expand Down
4 changes: 2 additions & 2 deletions accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestWatchNoDir(t *testing.T) {
t.Parallel()

// Create ks but not the directory that it watches.
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-watchnodir-test-%d-%d", os.Getpid(), rand.Int()))
ks := NewKeyStore(dir, LightScryptN, LightScryptP)

Expand Down Expand Up @@ -320,7 +320,7 @@ func TestUpdatedKeyfileContents(t *testing.T) {
t.Parallel()

// Create a temporary kesytore to test with
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-updatedkeyfilecontents-test-%d-%d", os.Getpid(), rand.Int()))
ks := NewKeyStore(dir, LightScryptN, LightScryptP)

Expand Down
2 changes: 1 addition & 1 deletion cmd/abidump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"encoding/hex"
"flag"
"fmt"
"github.com/PlatONnetwork/PlatON-Go/signer/core/apitypes"
"os"
"strings"

"github.com/PlatONnetwork/PlatON-Go/signer/core/apitypes"
"github.com/PlatONnetwork/PlatON-Go/signer/fourbyte"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/ctool/core/tx_stability.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func saveAddrs(addrs []string, pkFile string) {
addrsPath = filepath.Dir(pkFile) + "/addr.json"
}
os.Truncate(DefaultAccountAddrFilePath, 0)
byts, err := json.MarshalIndent(addrs, "", "\t")
_, err = os.Create(addrsPath)
byts, _ := json.MarshalIndent(addrs, "", "\t")
_, err := os.Create(addrsPath)
if err != nil {
panic(fmt.Errorf("create addr.json error%s \n", err.Error()))
}
Expand Down
48 changes: 4 additions & 44 deletions cmd/ctool/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"os"
"path/filepath"
"strings"

"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
"github.com/PlatONnetwork/PlatON-Go/rlp"
)

const (
Expand Down Expand Up @@ -161,8 +158,10 @@ func parseFuncFromAbi(fileName string, funcName string) (*FuncDesc, error) {
return nil, fmt.Errorf("function %s not found in %s", funcName, fileName)
}

/**
Find the method called by parsing abi
/*
*
Find the method called by parsing abi
*/
func GetFuncNameAndParams(f string) (string, []string) {
funcName := string(f[0:strings.Index(f, "(")])
Expand All @@ -181,42 +180,3 @@ func GetFuncNameAndParams(f string) (string, []string) {
return funcName, params

}

/**
Self-test method for encrypting parameters
*/
func encodeParam(abiPath string, funcName string, funcParams string) error {
// Determine if the method exists
abiFunc, err := parseFuncFromAbi(abiPath, funcName)
if err != nil {
return err
}

// Parsing the method of the call
funcName, inputParams := GetFuncNameAndParams(funcParams)

// Determine if the parameters are correct
if len(abiFunc.Inputs) != len(inputParams) {
return fmt.Errorf("incorrect number of parameters ,request=%d,get=%d\n", len(abiFunc.Inputs), len(inputParams))
}

paramArr := [][]byte{
Int32ToBytes(111),
[]byte(funcName),
}

for i, v := range inputParams {
input := abiFunc.Inputs[i]
p, e := StringConverter(v, input.Type)
if e != nil {
return err
}
paramArr = append(paramArr, p)
}

paramBytes, _ := rlp.EncodeToBytes(paramArr)

fmt.Printf(hexutil.Encode(paramBytes))

return nil
}
21 changes: 0 additions & 21 deletions common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,27 +152,6 @@ func (a Address) Hex() string {
return "0x" + a.HexWithNoPrefix()
}

func (a *Address) checksumHex() []byte {
buf := a.hex()

// compute checksum
sha := sha3.NewLegacyKeccak256()
sha.Write(buf[2:])
hash := sha.Sum(nil)
for i := 2; i < len(buf); i++ {
hashByte := hash[(i-2)/2]
if i%2 == 0 {
hashByte = hashByte >> 4
} else {
hashByte &= 0xf
}
if buf[i] > '9' && hashByte > 7 {
buf[i] -= 32
}
}
return buf[:]
}

func (a Address) hex() []byte {
var buf [len(a)*2 + 2]byte
copy(buf[:2], "0x")
Expand Down
11 changes: 5 additions & 6 deletions common/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"encoding/binary"
"encoding/hex"
"errors"
"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
"math"

"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
)

// FromHex returns the bytes represented by the hexadecimal string s.
Expand Down Expand Up @@ -117,23 +118,21 @@ func LeftPadBytes(slice []byte, l int) []byte {
}

func Int32ToBytes(n int32) []byte {
tmp := int32(n)
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, binary.BigEndian, tmp)
binary.Write(bytesBuffer, binary.BigEndian, n)
return bytesBuffer.Bytes()
}

func BytesToInt32(b []byte) int32 {
bytesBuffer := bytes.NewBuffer(b)
var tmp int32
binary.Read(bytesBuffer, binary.BigEndian, &tmp)
return int32(tmp)
return tmp
}

func Int64ToBytes(n int64) []byte {
tmp := int64(n)
bytesBuffer := bytes.NewBuffer([]byte{})
binary.Write(bytesBuffer, binary.BigEndian, tmp)
binary.Write(bytesBuffer, binary.BigEndian, n)
return bytesBuffer.Bytes()
}

Expand Down
12 changes: 6 additions & 6 deletions common/math/binomial_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ func TestBinomialDistribution(t *testing.T) {
}
}
bd = NewBinomialDistribution((1<<63)-1, p)
tp, err := bd.CumulativeProbability(int64(10000000))
_, err := bd.CumulativeProbability(int64(10000000))
if nil != err {
t.Error(err)
}
tp, err = bd.CumulativeProbability(int64(100000000))
_, err = bd.CumulativeProbability(int64(100000000))
if nil != err {
t.Error(err)
}
tp, err = bd.CumulativeProbability(int64(1000000000))
_, err = bd.CumulativeProbability(int64(1000000000))
if nil != err {
t.Error(err)
}
tp, err = bd.CumulativeProbability(int64(10000000000))
_, err = bd.CumulativeProbability(int64(10000000000))
if nil != err {
t.Error(err)
}
tp, err = bd.CumulativeProbability(int64(100000000000))
_, err = bd.CumulativeProbability(int64(100000000000))
if nil != err {
t.Error(err)
}
tp, err = bd.CumulativeProbability(int64(1000000000000))
_, err = bd.CumulativeProbability(int64(1000000000000))
if nil != err {
t.Error(err)
}
Expand Down
7 changes: 2 additions & 5 deletions common/mock/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ func (s *MockStateDB) SetState(adr common.Address, key, val []byte) {
func (s *MockStateDB) CreateAccount(addr common.Address) {
s.Journal.append(createObjectChange{account: &addr})

storage, ok := s.State[addr]
_, ok := s.State[addr]
if !ok {
storage = make(map[string][]byte)
storage := make(map[string][]byte)
s.State[addr] = storage
}
}
Expand Down Expand Up @@ -538,10 +538,8 @@ func (s *MockStateDB) GetCodeSize(addr common.Address) int {
}

func (s *MockStateDB) AddRefund(uint64) {
return
}
func (s *MockStateDB) SubRefund(uint64) {
return
}
func (s *MockStateDB) GetRefund() uint64 {
return 0
Expand Down Expand Up @@ -610,7 +608,6 @@ func (s *MockStateDB) GetLogs(hash common.Hash, blockHash common.Hash) []*types.
}

func (s *MockStateDB) AddPreimage(common.Hash, []byte) {
return
}

func (s *MockStateDB) ForEachStorage(addr common.Address, fn func([]byte, []byte) bool) {
Expand Down
5 changes: 3 additions & 2 deletions consensus/bft_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"bytes"
"errors"
"fmt"
"github.com/PlatONnetwork/PlatON-Go/core/rawdb"
"math/big"
"time"

"github.com/PlatONnetwork/PlatON-Go/core/rawdb"

"github.com/PlatONnetwork/PlatON-Go/p2p/enode"

"github.com/PlatONnetwork/PlatON-Go/ethdb"
Expand Down Expand Up @@ -109,7 +110,7 @@ func (bm *BftMock) InsertChain(block *types.Block) error {
}

if bm.chain != nil {
root := common.ZeroHash
var root common.Hash
if block.ParentHash() == bm.genesis.Hash() {
root = bm.genesis.Root()
} else if len(bm.Blocks) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion consensus/cbft/cbft_byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func FakeViewChangeQC(t *testing.T, node *TestCBFT, epoch, viewNumber uint64, no
assert.Nil(t, node.engine.signMsgByBls(v))
viewChanges[nodeIndex] = v
viewChangeQC := node.engine.generateViewChangeQC(viewChanges)
viewChangeQC.QCs = append(append(viewChangeQC.QCs, viewChangeQC.QCs[0]))
viewChangeQC.QCs = append(viewChangeQC.QCs, viewChangeQC.QCs[0])
return viewChangeQC
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/cbft/network/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ func (s *fakeCbft) Config() *types.Config {

// ReceiveMessage receives consensus messages.
func (s *fakeCbft) ReceiveMessage(msg *types.MsgInfo) error {
fmt.Println(fmt.Sprintf("ReceiveMessage, type: %T", msg.Msg))
fmt.Printf("ReceiveMessage, type: %T", msg.Msg)
return nil
}

// ReceiveSyncMsg receives synchronization messages.
func (s *fakeCbft) ReceiveSyncMsg(msg *types.MsgInfo) error {
fmt.Println(fmt.Sprintf("ReceiveSyncMsg, type: %T", msg.Msg))
fmt.Printf("ReceiveSyncMsg, type: %T", msg.Msg)
return nil
}

Expand Down
32 changes: 0 additions & 32 deletions consensus/cbft/network/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package network

import (
"crypto/rand"
"flag"
"fmt"
"math/big"
"testing"
Expand All @@ -37,8 +36,6 @@ import (
"github.com/PlatONnetwork/PlatON-Go/p2p"
)

var loglevel = flag.Int("loglevel", 4, "verbosity of logs")

// Create a new PrepareBlock for testing.
func newFakePrepareBlock() *protocols.PrepareBlock {
block := types.NewBlockWithHeader(&types.Header{
Expand Down Expand Up @@ -226,35 +223,6 @@ func newFakePong(pingTime string) *protocols.Pong {
}
}

// fakePeer is a simulated peer to allow testing direct network calls.
type fakePeer struct {
net p2p.MsgReadWriter // Network layer reader/writer to simulate remote messaging.
app *p2p.MsgPipeRW // Application layer reader/writer to simulate the local side.
*peer // The peer belonging to CBFT layer.
}

// newFakePeer creates a new peer registered at the given protocol manager.
func newFakePeer(name string, version int, pm *EngineManager, shake bool) (*fakePeer, <-chan error) {
// Create a message pipe to communicate through.
app, net := p2p.MsgPipe()

// Generate a random id and create the peer.
var id enode.ID
rand.Read(id[:])

// Create a peer that belonging to cbft.
peer := newPeer(version, p2p.NewPeer(id, name, nil), net)

// Start the peer on a new thread
errc := make(chan error, 1)
go func() {
//
errc <- pm.handler(peer.Peer, peer.rw)
}()
tp := &fakePeer{app: app, net: net, peer: peer}
return tp, errc
}

// Create a new peer for testing, return peer and ID.
func newTestPeer(version int, name string) (*peer, enode.ID) {
_, net := p2p.MsgPipe()
Expand Down
7 changes: 0 additions & 7 deletions consensus/cbft/network/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the PlatON-Go library. If not, see <http://www.gnu.org/licenses/>.


package network

import (
Expand Down Expand Up @@ -47,12 +46,6 @@ var (
propViewChangeOutPacketsMeter = metrics.NewRegisteredMeter("cbft/prop/view_change/out/packets", nil)
propViewChangeOutTrafficMeter = metrics.NewRegisteredMeter("cbft/prop/view_change/out/traffic", nil)

// PrepareBlockHashMsg
propPrepareBlockHashInPacketsMeter = metrics.NewRegisteredMeter("cbft/prop/prepare_block_hash/in/packets", nil)
propPrepareBlockHashInTrafficMeter = metrics.NewRegisteredMeter("cbft/prop/prepare_block_hash/in/traffic", nil)
propPrepareBlockHashOutPacketsMeter = metrics.NewRegisteredMeter("cbft/prop/prepare_block_hash/out/packets", nil)
propPrepareBlockHashOutTrafficMeter = metrics.NewRegisteredMeter("cbft/prop/prepare_block_hash/out/traffic", nil)

// GetPrepareBlockMsg
reqGetPrepareBlockInPacketsMeter = metrics.NewRegisteredMeter("cbft/req/get_prepare_block/in/packets", nil)
reqGetPrepareBlockInTrafficMeter = metrics.NewRegisteredMeter("cbft/req/get_prepare_block/in/traffic", nil)
Expand Down
Loading

0 comments on commit 3b97004

Please sign in to comment.