This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
forked from Roasbeef/btcd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
alert.go
57 lines (50 loc) · 1.46 KB
/
alert.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2013-2016 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package main
import (
"github.com/wakiyamap/monad/btcec"
"github.com/wakiyamap/monad/chaincfg/chainhash"
"github.com/wakiyamap/monad/checkpoint"
)
const (
checkpointWriteThreshol = 20
)
// alert payload's signature check
func CheckSignature(alertKey []byte, serializedPayload []byte, signature []byte) bool {
pAlertPubKey, err := btcec.ParsePubKey(alertKey, btcec.S256())
if err != nil {
return false
}
pSignature, err := btcec.ParseSignature(signature, btcec.S256())
if err != nil {
return false
}
if !pSignature.Verify(chainhash.DoubleHashB(serializedPayload), pAlertPubKey) {
return false
}
return true
}
// Writing the specified checkpoint.
func CmdCheckpoint(height int64, hash string, serverHeight int64, serverHash string, minVer int64) {
uc := checkpoint.GetUserCheckpointDbInstance()
ucMax := uc.GetMaxCheckpointHeight()
if height == minVer {
if height > ucMax && height < serverHeight {
if height >= ucMax+checkpointWriteThreshol {
if hash == serverHash {
uc.Add(height, hash)
}
}
vc := checkpoint.GetVolatileCheckpointDbInstance()
vc.Set(height, hash)
}
} else {
peerLog.Infof("ALERT, MinVer %v does not match %v", minVer, height)
}
}
// Invalidation of specified alertkey.
func CmdInvalidateKey(key string) {
ak := checkpoint.GetAlertKeyDbInstance()
ak.Set(key)
}