-
Notifications
You must be signed in to change notification settings - Fork 0
/
reorg.go
37 lines (29 loc) · 836 Bytes
/
reorg.go
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
package state
// Reorganize corrects an identified fork. No mining is allowed to take place
// while this process is running. New transactions can be placed into the mempool.
func (s *State) Reorganize() error {
s.mu.Lock()
defer s.mu.Unlock()
// Don't allow mining to continue.
s.allowMining = false
// Reset the state of the blockchain node.
s.db.Reset()
// Resync the state of the blockchain.
s.resyncWG.Add(1)
go func() {
s.evHandler("state: Resync: started: *****************************")
defer func() {
s.turnMiningOn()
s.evHandler("state: Resync: completed: *****************************")
s.resyncWG.Done()
}()
s.Worker.Sync()
}()
return nil
}
// turnMiningOn sets the allowMining flag back to true.
func (s *State) turnMiningOn() {
s.mu.Lock()
defer s.mu.Unlock()
s.allowMining = true
}