forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* event log * event log * event log * event log * event log * fix config * reuse code * fix * fix * fix Makefile * remove default config * remove default config * remove default config * remove default config
- Loading branch information
1 parent
2b94b84
commit 9453210
Showing
39 changed files
with
744 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,4 +145,3 @@ Enabled = false | |
ProfilingHost = "0.0.0.0" | ||
ProfilingPort = 6060 | ||
ProfilingEnabled = false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- +migrate Up | ||
DROP table state.event; | ||
DROP table state.debug; | ||
|
||
-- +migrate Down | ||
CREATE TABLE IF NOT EXISTS state.event | ||
( | ||
event_type VARCHAR NOT NULL, | ||
timestamp TIMESTAMP WITH TIME ZONE NOT NULL, | ||
ip VARCHAR, | ||
tx_hash VARCHAR, | ||
payload VARCHAR | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS state.debug | ||
( | ||
error_type VARCHAR, | ||
timestamp timestamp, | ||
payload VARCHAR | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE TYPE level_t AS ENUM ('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug'); | ||
|
||
CREATE TABLE public.event ( | ||
id BIGSERIAL PRIMARY KEY, | ||
received_at timestamp WITH TIME ZONE default CURRENT_TIMESTAMP, | ||
ip_address inet, | ||
source varchar(32) not null, | ||
component varchar(32), | ||
level level_t not null, | ||
event_id varchar(32) not null, | ||
description text, | ||
data bytea, | ||
json jsonb | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package event | ||
|
||
import "github.com/0xPolygonHermez/zkevm-node/db" | ||
|
||
// Config for event | ||
type Config struct { | ||
// DB is the database configuration | ||
DB db.Config `mapstructure:"DB"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package event | ||
|
||
import ( | ||
"math/big" | ||
"time" | ||
) | ||
|
||
// EventID is the ID of the event | ||
type EventID string | ||
|
||
// Source is the source of the event | ||
type Source string | ||
|
||
// Component is the component that triggered the event | ||
type Component string | ||
|
||
// Level is the level of the event | ||
type Level string | ||
|
||
const ( | ||
// EventID_NodeComponentStarted is triggered when the node starts | ||
EventID_NodeComponentStarted = "NODE COMPONENT STARTED" | ||
// EventID_PreexecutionOOC is triggered when an OOC error is detected during the preexecution | ||
EventID_PreexecutionOOC EventID = "PRE EXECUTION OOC" | ||
// EventID_PreexecutionOOG is triggered when an OOG error is detected during the preexecution | ||
EventID_PreexecutionOOG EventID = "PRE EXECUTION OOG" | ||
// EventID_ExecutorError is triggered when an error is detected during the execution | ||
EventID_ExecutorError EventID = "EXECUTOR ERROR" | ||
// EventID_ReprocessFullBatchOOC is triggered when an OOC error is detected during the reprocessing of a full batch | ||
EventID_ReprocessFullBatchOOC EventID = "REPROCESS FULL BATCH OOC" | ||
// EventID_ExecutorRLPError is triggered when an RLP error is detected during the execution | ||
EventID_ExecutorRLPError EventID = "EXECUTOR RLP ERROR" | ||
// EventID_FinalizerHalt is triggered when the finalizer halts | ||
EventID_FinalizerHalt EventID = "FINALIZER HALT" | ||
|
||
// Source_Node is the source of the event | ||
Source_Node Source = "node" | ||
|
||
// Component_RPC is the component that triggered the event | ||
Component_RPC Component = "rpc" | ||
// Component_Pool is the component that triggered the event | ||
Component_Pool Component = "pool" | ||
// Component_Sequencer is the component that triggered the event | ||
Component_Sequencer Component = "sequencer" | ||
// Component_Synchronizer is the component that triggered the event | ||
Component_Synchronizer Component = "synchronizer" | ||
// Component_Aggregator is the component that triggered the event | ||
Component_Aggregator Component = "aggregator" | ||
// Component_EthTxManager is the component that triggered the event | ||
Component_EthTxManager Component = "ethtxmanager" | ||
// Component_GasPricer is the component that triggered the event | ||
Component_GasPricer Component = "gaspricer" | ||
// Component_Executor is the component that triggered the event | ||
Component_Executor Component = "executor" | ||
// Component_Broadcast is the component that triggered the event | ||
Component_Broadcast Component = "broadcast" | ||
|
||
// Level_Emergency is the most severe level | ||
Level_Emergency Level = "emerg" | ||
// Level_Alert is the second most severe level | ||
Level_Alert Level = "alert" | ||
// Level_Critical is the third most severe level | ||
Level_Critical Level = "crit" | ||
// Level_Error is the fourth most severe level | ||
Level_Error Level = "err" | ||
// Level_Warning is the fifth most severe level | ||
Level_Warning Level = "warning" | ||
// Level_Notice is the sixth most severe level | ||
Level_Notice Level = "notice" | ||
// Level_Info is the seventh most severe level | ||
Level_Info Level = "info" | ||
// Level_Debug is the least severe level | ||
Level_Debug Level = "debug" | ||
) | ||
|
||
// Event represents a event that may be investigated | ||
type Event struct { | ||
Id big.Int | ||
ReceivedAt time.Time | ||
IPAddress string | ||
Source Source | ||
Component Component | ||
Level Level | ||
EventID EventID | ||
Description string | ||
Data []byte | ||
Json interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package event | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/0xPolygonHermez/zkevm-node/log" | ||
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor/pb" | ||
) | ||
|
||
// EventLog is the main struct for the event log | ||
type EventLog struct { | ||
cfg Config | ||
storage Storage | ||
} | ||
|
||
// NewEventLog creates and initializes an instance of EventLog | ||
func NewEventLog(cfg Config, storage Storage) *EventLog { | ||
return &EventLog{ | ||
cfg: cfg, | ||
storage: storage, | ||
} | ||
} | ||
|
||
// LogEvent is used to store an event for runtime debugging | ||
func (e *EventLog) LogEvent(ctx context.Context, event *Event) error { | ||
return e.storage.LogEvent(ctx, event) | ||
} | ||
|
||
// LogExecutorError is used to store Executor error for runtime debugging | ||
func (e *EventLog) LogExecutorError(ctx context.Context, responseError pb.ExecutorError, processBatchRequest *pb.ProcessBatchRequest) { | ||
timestamp := time.Now() | ||
log.Errorf("error found in the executor: %v at %v", responseError, timestamp) | ||
payload, err := json.Marshal(processBatchRequest) | ||
if err != nil { | ||
log.Errorf("error marshaling payload: %v", err) | ||
} else { | ||
event := &Event{ | ||
ReceivedAt: timestamp, | ||
Source: Source_Node, | ||
Component: Component_Executor, | ||
Level: Level_Error, | ||
EventID: EventID_ExecutorError, | ||
Description: responseError.String(), | ||
Json: string(payload), | ||
} | ||
err = e.storage.LogEvent(ctx, event) | ||
if err != nil { | ||
log.Errorf("error storing event: %v", err) | ||
} | ||
} | ||
} |
Oops, something went wrong.