forked from FactomProject/FactomCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmempool.go
More file actions
86 lines (66 loc) · 2.05 KB
/
mempool.go
File metadata and controls
86 lines (66 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2015 FactomProject Authors. All rights reserved.
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package process
import (
"errors"
"github.com/FactomProject/FactomCode/common"
"github.com/FactomProject/btcd/wire"
"sync"
"time"
)
// ftmMemPool is used as a source of factom transactions
// (CommitChain, RevealChain, CommitEntry, RevealEntry)
type ftmMemPool struct {
sync.RWMutex
pool map[wire.ShaHash]wire.Message
orphans map[wire.ShaHash]wire.Message
blockpool map[string]wire.Message // to hold the blocks or entries downloaded from peers
lastUpdated time.Time // last time pool was updated
}
// Add a factom message to the orphan pool
func (mp *ftmMemPool) init_ftmMemPool() error {
mp.pool = make(map[wire.ShaHash]wire.Message)
mp.orphans = make(map[wire.ShaHash]wire.Message)
mp.blockpool = make(map[string]wire.Message)
return nil
}
// Add a factom message to the Mem pool
func (mp *ftmMemPool) addMsg(msg wire.Message, hash *wire.ShaHash) error {
mp.Lock()
defer mp.Unlock()
if len(mp.pool) > common.MAX_TX_POOL_SIZE {
return errors.New("Transaction mem pool exceeds the limit.")
}
mp.pool[*hash] = msg
return nil
}
// Add a factom message to the orphan pool
func (mp *ftmMemPool) addOrphanMsg(msg wire.Message, hash *wire.ShaHash) error {
mp.Lock()
defer mp.Unlock()
if len(mp.orphans) > common.MAX_ORPHAN_SIZE {
return errors.New("Ophan mem pool exceeds the limit.")
}
mp.orphans[*hash] = msg
return nil
}
// Add a factom block message to the Mem pool
func (mp *ftmMemPool) addBlockMsg(msg wire.Message, hash string) error {
mp.Lock()
defer mp.Unlock()
if len(mp.blockpool) > common.MAX_BLK_POOL_SIZE {
return errors.New("Block mem pool exceeds the limit. Please restart.")
}
mp.blockpool[hash] = msg
return nil
}
// Delete a factom block message from the Mem pool
func (mp *ftmMemPool) deleteBlockMsg(hash string) error {
mp.Lock()
defer mp.Unlock()
if mp.blockpool[hash] != nil {
delete(fMemPool.blockpool, hash)
}
return nil
}