Skip to content

Commit

Permalink
Merge branch 'master' into fix_gosec_fileinclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
huof6829 committed Jul 15, 2022
2 parents a9d971d + ad61fa3 commit bd19361
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
8 changes: 4 additions & 4 deletions action/consignment_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type (

// ConsignMsgEther is the consignment message format of Ethereum
ConsignMsgEther struct {
BucketIdx int `json:"bucket"`
Nonce int `json:"nonce"`
BucketIdx uint64 `json:"bucket"`
Nonce uint64 `json:"nonce"`
Recipient string `json:"recipient"`
Reclaim string `json:"reclaim"`
}
Expand Down Expand Up @@ -148,8 +148,8 @@ func NewConsignMsg(sigType, recipient string, bucketIdx, nonce uint64) ([]byte,
switch sigType {
case "Ethereum":
msg := ConsignMsgEther{
BucketIdx: int(bucketIdx),
Nonce: int(nonce),
BucketIdx: bucketIdx,
Nonce: nonce,
Recipient: recipient,
Reclaim: _reclaim,
}
Expand Down
4 changes: 2 additions & 2 deletions action/protocol/staking/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@ func TestProtocol_HandleConsignmentTransfer(t *testing.T) {
// transfer to test.to through consignment
var consign []byte
if !test.nilPayload {
consign = newconsignment(require, int(test.sigIndex), int(test.sigNonce), test.bucketOwner, test.to.String(), test.consignType, test.reclaim, test.wrongSig)
consign = newconsignment(require, test.sigIndex, test.sigNonce, test.bucketOwner, test.to.String(), test.consignType, test.reclaim, test.wrongSig)
}

act, err := action.NewTransferStake(1, caller.String(), 0, consign, gasLimit, gasPrice)
Expand Down Expand Up @@ -2713,7 +2713,7 @@ func depositGas(ctx context.Context, sm protocol.StateManager, gasFee *big.Int)
return nil, accountutil.StoreAccount(sm, actionCtx.Caller, acc)
}

func newconsignment(r *require.Assertions, bucketIdx, nonce int, senderPrivate, recipient, consignTpye, reclaim string, wrongSig bool) []byte {
func newconsignment(r *require.Assertions, bucketIdx, nonce uint64, senderPrivate, recipient, consignTpye, reclaim string, wrongSig bool) []byte {
msg := action.ConsignMsgEther{
BucketIdx: bucketIdx,
Nonce: nonce,
Expand Down
19 changes: 9 additions & 10 deletions blockchain/integrity/integrity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"encoding/hex"
"fmt"
"math/big"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -832,22 +832,17 @@ func TestBlockchain_MintNewBlock_PopAccount(t *testing.T) {
}

type MockSubscriber struct {
counter int
mu sync.RWMutex
counter int32
}

func (ms *MockSubscriber) ReceiveBlock(blk *block.Block) error {
ms.mu.Lock()
tsfs, _ := classifyActions(blk.Actions)
ms.counter += len(tsfs)
ms.mu.Unlock()
atomic.AddInt32(&ms.counter, int32(len(tsfs)))
return nil
}

func (ms *MockSubscriber) Counter() int {
ms.mu.RLock()
defer ms.mu.RUnlock()
return ms.counter
return int(atomic.LoadInt32(&ms.counter))
}

func TestConstantinople(t *testing.T) {
Expand Down Expand Up @@ -1142,8 +1137,12 @@ func TestLoadBlockchainfromDB(t *testing.T) {
height := bc.TipHeight()
fmt.Printf("Open blockchain pass, height = %d\n", height)
require.NoError(addTestingTsfBlocks(cfg, bc, dao, ap))
//make sure pubsub is completed
err = testutil.WaitUntil(200*time.Millisecond, 3*time.Second, func() (bool, error) {
return 24 == ms.Counter(), nil
})
require.NoError(err)
require.NoError(bc.Stop(ctx))
require.Equal(24, ms.Counter())

// Load a blockchain from DB
bc = blockchain.NewBlockchain(
Expand Down
4 changes: 2 additions & 2 deletions blockchain/pubsubmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (ps *pubSub) RemoveBlockListener(s BlockCreationSubscriber) error {

// SendBlockToSubscribers sends block to every subscriber by using buffer channel
func (ps *pubSub) SendBlockToSubscribers(blk *block.Block) {
ps.lock.Lock()
defer ps.lock.Unlock()
ps.lock.RLock()
defer ps.lock.RUnlock()
for _, elem := range ps.blocklisteners {
elem.pendingBlksBuffer <- blk
}
Expand Down
12 changes: 7 additions & 5 deletions ioctl/cmd/bc/bcbucketlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,26 @@ func (m *bucketlistMessage) String() string {

// getBucketList get bucket list from chain
func getBucketList(method, addr string, args ...string) (err error) {
offset, limit := uint64(0), uint64(1000)
offset, limit := uint32(0), uint32(1000)
if len(args) > 0 {
offset, err = strconv.ParseUint(args[0], 10, 64)
val, err := strconv.ParseUint(args[0], 10, 32)
if err != nil {
return output.NewError(output.ValidationError, "invalid offset", err)
}
offset = uint32(val)
}
if len(args) > 1 {
limit, err = strconv.ParseUint(args[1], 10, 64)
val, err := strconv.ParseUint(args[1], 10, 32)
if err != nil {
return output.NewError(output.ValidationError, "invalid limit", err)
}
limit = uint32(val)
}
switch method {
case _bucketlistMethodByVoter:
return getBucketListByVoter(addr, uint32(offset), uint32(limit))
return getBucketListByVoter(addr, offset, limit)
case _bucketlistMethodByCandidate:
return getBucketListByCand(addr, uint32(offset), uint32(limit))
return getBucketListByCand(addr, offset, limit)
}
return output.NewError(output.InputError, "unknown <method>", nil)
}
Expand Down
17 changes: 10 additions & 7 deletions ioctl/newcmd/bc/bcbucketlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,40 @@ func NewBCBucketListCmd(client ioctl.Client) *cobra.Command {
err error
)

offset, limit := uint64(0), uint64(1000)
method, addr := args[0], args[1]
s := args[2:]
offset, limit := uint32(0), uint32(1000)
method, addr, s := args[0], args[1], args[2:]

if len(s) > 0 {
offset, err = strconv.ParseUint(s[0], 10, 64)
val, err := strconv.ParseUint(s[0], 10, 32)
if err != nil {
return errors.Wrap(err, "invalid offset")
}
offset = uint32(val)
}
if len(s) > 1 {
limit, err = strconv.ParseUint(s[1], 10, 64)
val, err := strconv.ParseUint(s[1], 10, 32)
if err != nil {
return errors.Wrap(err, "invalid limit")
}
limit = uint32(val)
}

switch method {
case MethodVoter:
address, err = client.AddressWithDefaultIfNotExist(addr)
if err != nil {
return err
}
bl, err = getBucketListByVoterAddress(client, address, uint32(offset), uint32(limit))
bl, err = getBucketListByVoterAddress(client, address, offset, limit)
case MethodCandidate:
bl, err = getBucketListByCandidateName(client, addr, uint32(offset), uint32(limit))
bl, err = getBucketListByCandidateName(client, addr, offset, limit)
default:
return errors.New("unknown <method>")
}
if err != nil {
return err
}

var lines []string
if len(bl.Buckets) == 0 {
lines = append(lines, "Empty bucketlist with given address")
Expand Down

0 comments on commit bd19361

Please sign in to comment.