[webhooks] Additional support for downstream monitoring (#2434)

* [webhook] Move webhook with call for when cannot commit block

* [webhook] Move as own root package

* [webhook] Report bad block to webhook
pull/2436/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 8d18c5a987
commit 62e6fcfcf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmd/harmony/main.go
  2. 2
      internal/configs/node/config.go
  3. 2
      node/node.go
  4. 15
      node/node_handler.go
  5. 4
      staking/slash/webhook.example.yaml
  6. 8
      webhooks/webhook.example.yaml
  7. 12
      webhooks/yaml.go

@ -40,7 +40,7 @@ import (
"github.com/harmony-one/harmony/p2p/p2pimpl" "github.com/harmony-one/harmony/p2p/p2pimpl"
p2putils "github.com/harmony-one/harmony/p2p/utils" p2putils "github.com/harmony-one/harmony/p2p/utils"
"github.com/harmony-one/harmony/shard" "github.com/harmony-one/harmony/shard"
"github.com/harmony-one/harmony/staking/webhooks" "github.com/harmony-one/harmony/webhooks"
golog "github.com/ipfs/go-log" golog "github.com/ipfs/go-log"
"github.com/pkg/errors" "github.com/pkg/errors"
gologging "github.com/whyrusleeping/go-logging" gologging "github.com/whyrusleeping/go-logging"

@ -13,7 +13,7 @@ import (
"github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/multibls" "github.com/harmony-one/harmony/multibls"
"github.com/harmony-one/harmony/shard" "github.com/harmony-one/harmony/shard"
"github.com/harmony-one/harmony/staking/webhooks" "github.com/harmony-one/harmony/webhooks"
p2p_crypto "github.com/libp2p/go-libp2p-crypto" p2p_crypto "github.com/libp2p/go-libp2p-crypto"
"github.com/pkg/errors" "github.com/pkg/errors"
) )

@ -38,7 +38,7 @@ import (
"github.com/harmony-one/harmony/shard/committee" "github.com/harmony-one/harmony/shard/committee"
"github.com/harmony-one/harmony/staking/slash" "github.com/harmony-one/harmony/staking/slash"
staking "github.com/harmony-one/harmony/staking/types" staking "github.com/harmony-one/harmony/staking/types"
"github.com/harmony-one/harmony/staking/webhooks" "github.com/harmony-one/harmony/webhooks"
) )
// State is a state of a node. // State is a state of a node.

@ -25,7 +25,7 @@ import (
"github.com/harmony-one/harmony/staking/availability" "github.com/harmony-one/harmony/staking/availability"
"github.com/harmony-one/harmony/staking/slash" "github.com/harmony-one/harmony/staking/slash"
staking "github.com/harmony-one/harmony/staking/types" staking "github.com/harmony-one/harmony/staking/types"
"github.com/harmony-one/harmony/staking/webhooks" "github.com/harmony-one/harmony/webhooks"
libp2p_peer "github.com/libp2p/go-libp2p-core/peer" libp2p_peer "github.com/libp2p/go-libp2p-core/peer"
) )
@ -363,6 +363,17 @@ func (node *Node) VerifyNewBlock(newBlock *types.Block) error {
} }
if err := node.Blockchain().ValidateNewBlock(newBlock); err != nil { if err := node.Blockchain().ValidateNewBlock(newBlock); err != nil {
if hooks := node.NodeConfig.WebHooks.Hooks; hooks != nil {
if p := hooks.ProtocolIssues; p != nil {
url := p.OnCannotCommit
go func() {
webhooks.DoPost(url, map[string]interface{}{
"bad-header": newBlock.Header().String(),
"reason": err.Error(),
})
}()
}
}
utils.Logger().Error(). utils.Logger().Error().
Str("blockHash", newBlock.Hash().Hex()). Str("blockHash", newBlock.Hash().Hex()).
Int("numTx", len(newBlock.Transactions())). Int("numTx", len(newBlock.Transactions())).
@ -479,7 +490,7 @@ func (node *Node) PostConsensusProcessing(
signed, toSign, quotient, err := signed, toSign, quotient, err :=
availability.ComputeCurrentSigning(snapshot, wrapper) availability.ComputeCurrentSigning(snapshot, wrapper)
if err != nil && availability.IsBelowSigningThreshold(quotient) { if err != nil && availability.IsBelowSigningThreshold(quotient) {
url := h.Availability.DroppedBelowThreshold url := h.Availability.OnDroppedBelowThreshold
go func() { go func() {
webhooks.DoPost(url, staking.Computed{signed, toSign, quotient}) webhooks.DoPost(url, staking.Computed{signed, toSign, quotient})
}() }()

@ -1,4 +0,0 @@
web-hooks:
# node will call these webhooks
notice-double-sign: http://localhost:5430/on-notice-double-sign
this-node-double-signed: http://localhost:5430/on-this-node-double-signed

@ -0,0 +1,8 @@
slashing-hooks:
on-notice-double-sign: http://localhost:5430/on-notice-double-sign
availability-hooks:
on-dropped-below-threshold: http://localhost:5430/on-dropped-below-threshold
protocol-hooks:
on-cannot-commit-block: http://localhost:5430/on-cannot-commit-block

@ -11,23 +11,29 @@ import (
const ( const (
// DefaultWebHookPath .. // DefaultWebHookPath ..
DefaultWebHookPath = "staking/webhooks/webhook.example.yaml" DefaultWebHookPath = "webhooks/webhook.example.yaml"
) )
// AvailabilityHooks .. // AvailabilityHooks ..
type AvailabilityHooks struct { type AvailabilityHooks struct {
DroppedBelowThreshold string `yaml:"dropped-below-threshold"` OnDroppedBelowThreshold string `yaml:"on-dropped-below-threshold"`
} }
// DoubleSignWebHooks .. // DoubleSignWebHooks ..
type DoubleSignWebHooks struct { type DoubleSignWebHooks struct {
OnNoticeDoubleSign string `yaml:"notice-double-sign"` OnNoticeDoubleSign string `yaml:"on-notice-double-sign"`
}
// BadBlockHooks ..
type BadBlockHooks struct {
OnCannotCommit string `yaml:"on-cannot-commit-block"`
} }
// Hooks .. // Hooks ..
type Hooks struct { type Hooks struct {
Slashing *DoubleSignWebHooks `yaml:"slashing-hooks"` Slashing *DoubleSignWebHooks `yaml:"slashing-hooks"`
Availability *AvailabilityHooks `yaml:"availability-hooks"` Availability *AvailabilityHooks `yaml:"availability-hooks"`
ProtocolIssues *BadBlockHooks `yaml:"protocol-hooks"`
} }
// ReportResult .. // ReportResult ..
Loading…
Cancel
Save