Skip to content

Commit

Permalink
Merge branch 'feature/bump-version-to-1.5.1' into feature/bump-versio…
Browse files Browse the repository at this point in the history
…n-to-1.5.1
  • Loading branch information
benbaley authored May 7, 2024
2 parents 3d42c9b + 6b5ae2d commit 1cb635d
Show file tree
Hide file tree
Showing 52 changed files with 1,402 additions and 647 deletions.
15 changes: 7 additions & 8 deletions accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"sync"
"time"

mapset "github.com/deckarep/golang-set"
mapset "github.com/deckarep/golang-set/v2"

"github.com/PlatONnetwork/PlatON-Go/accounts"
"github.com/PlatONnetwork/PlatON-Go/common"
Expand Down Expand Up @@ -80,7 +80,7 @@ func newAccountCache(keydir string) (*accountCache, chan struct{}) {
keydir: keydir,
byAddr: make(map[common.Address][]accounts.Account),
notify: make(chan struct{}, 1),
fileC: fileCache{all: mapset.NewThreadUnsafeSet()},
fileC: fileCache{all: mapset.NewThreadUnsafeSet[string]()},
}
ac.watcher = newWatcher(ac)
return ac, ac.notify
Expand Down Expand Up @@ -281,16 +281,15 @@ func (ac *accountCache) scanAccounts() error {
// Process all the file diffs
start := time.Now()

for _, p := range creates.ToSlice() {
if a := readAccount(p.(string)); a != nil {
for _, path := range creates.ToSlice() {
if a := readAccount(path); a != nil {
ac.add(*a)
}
}
for _, p := range deletes.ToSlice() {
ac.deleteByFile(p.(string))
for _, path := range deletes.ToSlice() {
ac.deleteByFile(path)
}
for _, p := range updates.ToSlice() {
path := p.(string)
for _, path := range updates.ToSlice() {
ac.deleteByFile(path)
if a := readAccount(path); a != nil {
ac.add(*a)
Expand Down
17 changes: 9 additions & 8 deletions accounts/keystore/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ import (
"sync"
"time"

mapset "github.com/deckarep/golang-set/v2"

"github.com/PlatONnetwork/PlatON-Go/log"
mapset "github.com/deckarep/golang-set"
)

// fileCache is a cache of files seen during scan of keystore.
type fileCache struct {
all mapset.Set // Set of all files from the keystore folder
lastMod time.Time // Last time instance when a file was modified
all mapset.Set[string] // Set of all files from the keystore folder
lastMod time.Time // Last time instance when a file was modified
mu sync.Mutex
}

// scan performs a new scan on the given directory, compares against the already
// cached filenames, and returns file sets: creates, deletes, updates.
func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, error) {
func (fc *fileCache) scan(keyDir string) (mapset.Set[string], mapset.Set[string], mapset.Set[string], error) {
t0 := time.Now()

// List all the failes from the keystore folder
// List all the files from the keystore folder
files, err := os.ReadDir(keyDir)
if err != nil {
return nil, nil, nil, err
Expand All @@ -50,8 +51,8 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
defer fc.mu.Unlock()

// Iterate all the files and gather their metadata
all := mapset.NewThreadUnsafeSet()
mods := mapset.NewThreadUnsafeSet()
all := mapset.NewThreadUnsafeSet[string]()
mods := mapset.NewThreadUnsafeSet[string]()

var newLastMod time.Time
for _, fi := range files {
Expand All @@ -61,7 +62,7 @@ func (fc *fileCache) scan(keyDir string) (mapset.Set, mapset.Set, mapset.Set, er
log.Trace("Ignoring file on account scan", "path", path)
continue
}
// Gather the set of all and fresly modified files
// Gather the set of all and freshly modified files
all.Add(path)

info, err := fi.Info()
Expand Down
17 changes: 13 additions & 4 deletions common/mock/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"golang.org/x/crypto/sha3"

"github.com/PlatONnetwork/PlatON-Go/crypto"
"github.com/PlatONnetwork/PlatON-Go/params"
"github.com/PlatONnetwork/PlatON-Go/rlp"

"github.com/PlatONnetwork/PlatON-Go/core/snapshotdb"
Expand Down Expand Up @@ -90,7 +91,7 @@ func (c *Chain) AddBlock() {

func (c *Chain) AddBlockWithTxHash(txHash common.Hash) {
c.AddBlock()
c.StateDB.Prepare(txHash, 1)
c.StateDB.SetTxContext(txHash, 1)
}

func (c *Chain) SetHeaderTimeGenerate(f func(uint64) uint64) {
Expand All @@ -108,7 +109,7 @@ func (c *Chain) AddBlockWithTxHashAndCommit(txHash common.Hash, miner bool, f fu

func (c *Chain) execTx(miner bool, f Transaction) error {
c.StateDB.TxIndex++
c.StateDB.Prepare(f.Hash(), c.StateDB.TxIndex)
c.StateDB.SetTxContext(f.Hash(), c.StateDB.TxIndex)
if miner {
return f(common.ZeroHash, c.CurrentHeader(), c.StateDB, c.SnapDB)
} else {
Expand Down Expand Up @@ -396,7 +397,7 @@ type MockStateDB struct {
accessList *accessList
}

func (s *MockStateDB) Prepare(thash common.Hash, ti int) {
func (s *MockStateDB) SetTxContext(thash common.Hash, ti int) {
s.Thash = thash
s.TxIndex = ti
}
Expand Down Expand Up @@ -471,6 +472,14 @@ func (s *MockStateDB) SetState(adr common.Address, key, val []byte) {
}
}

func (s *MockStateDB) GetTransientState(addr common.Address, key []byte) []byte {
return nil
}

func (s *MockStateDB) SetTransientState(adr common.Address, key, val []byte) {

}

func (s *MockStateDB) CreateAccount(addr common.Address) {
s.Journal.append(createObjectChange{account: &addr})

Expand Down Expand Up @@ -624,7 +633,7 @@ func (s *MockStateDB) TxIdx() uint32 {
return uint32(s.TxIndex)
}

func (s *MockStateDB) PrepareAccessList(common.Address, *common.Address, []common.Address, types.AccessList) {
func (s *MockStateDB) Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList) {
}

func (s *MockStateDB) AddressInAccessList(addr common.Address) bool {
Expand Down
3 changes: 3 additions & 0 deletions consensus/bft_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

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

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

Expand All @@ -42,6 +43,7 @@ import (
"github.com/PlatONnetwork/PlatON-Go/rpc"

ctypes "github.com/PlatONnetwork/PlatON-Go/consensus/cbft/types"
"github.com/PlatONnetwork/PlatON-Go/x/gov"
)

type Chain interface {
Expand Down Expand Up @@ -120,6 +122,7 @@ func (bm *BftMock) InsertChain(block *types.Block) error {
}

statedb, err := bm.chain.StateAt(root)
gov.AddActiveVersion(params.FORKVERSION_1_6_0, 1, statedb)
if err != nil {
return err
}
Expand Down
11 changes: 6 additions & 5 deletions consensus/cbft/cbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ import (

"github.com/PlatONnetwork/PlatON-Go/consensus/misc"

mapset "github.com/deckarep/golang-set"
mapset "github.com/deckarep/golang-set/v2"

"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
"github.com/PlatONnetwork/PlatON-Go/p2p/enode"
"github.com/PlatONnetwork/PlatON-Go/trie"

"github.com/PlatONnetwork/PlatON-Go/crypto/bls"
"github.com/pkg/errors"

"github.com/PlatONnetwork/PlatON-Go/crypto/bls"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/consensus"
"github.com/PlatONnetwork/PlatON-Go/consensus/cbft/evidence"
Expand Down Expand Up @@ -175,7 +176,7 @@ type Cbft struct {
// Record message repetitions.
statQueues map[common.Hash]map[string]int
statQueuesLock sync.RWMutex
messageHashCache mapset.Set
messageHashCache mapset.Set[common.Hash]

// Delay time of each node
netLatencyMap map[string]*list.List
Expand Down Expand Up @@ -207,7 +208,7 @@ func New(sysConfig *params.CbftConfig, optConfig *ctypes.OptionsConfig, eventMux
nodeServiceContext: ctx,
queues: make(map[string]int),
statQueues: make(map[common.Hash]map[string]int),
messageHashCache: mapset.NewSet(),
messageHashCache: mapset.NewSet[common.Hash](),
netLatencyMap: make(map[string]*list.List),
}

Expand Down Expand Up @@ -391,7 +392,7 @@ func (cbft *Cbft) statMessage(msg *ctypes.MsgInfo) error {
defer cbft.statQueuesLock.Unlock()

for cbft.messageHashCache.Cardinality() >= maxStatQueuesSize {
msgHash := cbft.messageHashCache.Pop().(common.Hash)
msgHash, _ := cbft.messageHashCache.Pop()
// Printout.
var bf bytes.Buffer
for k, v := range cbft.statQueues[msgHash] {
Expand Down
6 changes: 3 additions & 3 deletions consensus/cbft/network/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

"github.com/PlatONnetwork/PlatON-Go/consensus/cbft/types"

mapset "github.com/deckarep/golang-set"
mapset "github.com/deckarep/golang-set/v2"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/log"
Expand Down Expand Up @@ -82,7 +82,7 @@ type peer struct {
// Record the message received by the peer node.
// If the threshold is exceeded, the queue tail
// record is popped up and then added.
knownMessageHash mapset.Set
knownMessageHash mapset.Set[common.Hash]

pingList *list.List
listLock sync.RWMutex
Expand All @@ -103,7 +103,7 @@ func newPeer(pv int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
highestQCBn: new(big.Int),
lockedBn: new(big.Int),
commitBn: new(big.Int),
knownMessageHash: mapset.NewSet(),
knownMessageHash: mapset.NewSet[common.Hash](),
pingList: list.New(),
sendQueue: make(chan *types.MsgPackage, maxQueueSize),
}
Expand Down
Loading

0 comments on commit 1cb635d

Please sign in to comment.