Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc/v1.6.0 #80

Merged
merged 96 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
528193f
adapt to use new structs from core
ssd04 Mar 21, 2023
ca1ae85
addapt pub key converter mock
ssd04 Mar 22, 2023
7331812
fully integrate outportBlock struct and fix tests
ssd04 Mar 22, 2023
41fd161
fix ws integration tests
ssd04 Mar 22, 2023
15e044f
fix obs tool
ssd04 Mar 22, 2023
e2b57c1
fixes after review
ssd04 Mar 23, 2023
a4e349e
refactor to use marshaller and pubkey converter from config
ssd04 Mar 26, 2023
25f60a9
added todo for marshaller factory
ssd04 Mar 27, 2023
8b83d58
Update api/groups/eventsData.go
ssd04 Mar 27, 2023
52b30ca
fixes after review
ssd04 Mar 27, 2023
b5c9f35
fixes after review: renaming, refactor
ssd04 Mar 27, 2023
229b2e1
use marshalizer mock from core
ssd04 Mar 27, 2023
201baba
Merge pull request #68 from multiversx/integrate-new-structures
ssd04 Mar 27, 2023
f82cc4b
conflicts fixes
ssd04 Mar 27, 2023
6f36219
Update config/config.go
ssd04 Mar 27, 2023
44214dc
Merge pull request #69 from multiversx/marshaller-factory
ssd04 Mar 27, 2023
0ac1b3e
integrate new block getheader
ssd04 Mar 28, 2023
43ac689
fix nil block inner fields
ssd04 Mar 28, 2023
11fc2e4
added events data handler component
ssd04 Mar 29, 2023
b2a4106
unit tests for events data handler component
ssd04 Mar 29, 2023
cbef82a
events data handler renamings
ssd04 Mar 29, 2023
24f6cec
separate marshaller for internal marshalling + renamings
ssd04 Mar 29, 2023
47f2cc6
fix integration tests
ssd04 Mar 29, 2023
63b7beb
Merge pull request #70 from multiversx/fix-header-handling
ssd04 Apr 6, 2023
89368fc
latest core version for outport driver
ssd04 Jun 6, 2023
fc99ef8
fix outport block reference
ssd04 Jun 6, 2023
01d73bf
Merge pull request #72 from multiversx/outport-driver-latest-core
ssd04 Jun 6, 2023
5b72f99
added ws connector
ssd04 Jun 7, 2023
aa24692
integrate ws connector
ssd04 Jun 7, 2023
1f11210
renamings and comments updates
ssd04 Jun 8, 2023
e8da75b
unit test for events preprocessor
ssd04 Jun 8, 2023
8d77eb6
unit test for events indexer
ssd04 Jun 8, 2023
7309c22
added todo for refactoring old setup
ssd04 Jun 8, 2023
395b9b0
rename websocket connector fields
ssd04 Jun 8, 2023
6d5447d
fixes after review: use hex encoding
ssd04 Jun 8, 2023
cc40e5b
addapt integration tests to work with observer connector
ssd04 Jun 9, 2023
5c0a485
adapt api events group revert and finalized routes
ssd04 Jun 12, 2023
7785bc8
adapt integration test for revert and finalized events
ssd04 Jun 12, 2023
892ec7d
fix header hash reference
ssd04 Jun 12, 2023
345836e
fix header hash encoding
ssd04 Jun 12, 2023
b1d8db7
integration tests for both http and ws observer connector
ssd04 Jun 12, 2023
931b9ee
fix events group unit tests
ssd04 Jun 12, 2023
d161b52
added ws connector marshaller
ssd04 Jun 12, 2023
d52c9e1
fix integration tests timing
ssd04 Jun 12, 2023
b0df80c
fixes after review
ssd04 Jun 12, 2023
4fd6ff3
add cli flag for observer connector type
ssd04 Jun 14, 2023
31e16a1
adapt integration tests
ssd04 Jun 14, 2023
211567a
fix makefile var reference
ssd04 Jun 14, 2023
398e4b3
Merge pull request #73 from multiversx/websocket-connector
ssd04 Jun 14, 2023
7c9e89d
fix after review
ssd04 Jun 22, 2023
071cb9d
Merge branch 'feat/outport-refactor' into websocket-connector-integra…
ssd04 Jun 22, 2023
b57dad6
fix get random port
ssd04 Jun 22, 2023
058d57d
remove sleep times
ssd04 Jun 22, 2023
55996a6
use wait group + increase sleep time
ssd04 Jun 22, 2023
f398509
cleanup api events data handler
ssd04 Jun 22, 2023
b726e99
change mutex in rabbitclient mock
ssd04 Jun 22, 2023
c64720b
refactored marshallers + small updates
ssd04 Jul 3, 2023
da4dbc2
refactor wait timeout func
ssd04 Jul 4, 2023
6f7d2f6
update comment for wait timeout
ssd04 Jul 4, 2023
51e445d
Merge pull request #75 from multiversx/websocket-connector-integratio…
ssd04 Jul 10, 2023
52f134c
Merge pull request #71 from multiversx/feat/outport-refactor
ssd04 Sep 13, 2023
bb432ef
Merge branch 'main' into merge-main-into-rc-1.6.0
ssd04 Sep 14, 2023
24806c0
Merge pull request #79 from multiversx/merge-main-into-rc-1.6.0
ssd04 Sep 15, 2023
9be981d
change api cli flag to publisher
ssd04 Sep 15, 2023
73a949b
update readme with new flag
ssd04 Sep 15, 2023
61aa9cf
rename events indexer
ssd04 Sep 19, 2023
8f26ce0
tools for payload integrations testing
ssd04 Sep 20, 2023
1c9f204
payload versioning integration
ssd04 Sep 20, 2023
49e5d67
adapt to use uint32 version
ssd04 Sep 20, 2023
ac66ac1
handle version based on http header
ssd04 Sep 21, 2023
0198a8e
unit tests for payload versioning
ssd04 Sep 21, 2023
eed7675
default payload version for http connector
ssd04 Sep 21, 2023
b8ef351
refactor version header check
ssd04 Sep 21, 2023
92fc39b
separte payload handler for http and ws connector:
ssd04 Sep 21, 2023
d40b6ab
remove unused rabbit publisher tool code
ssd04 Sep 21, 2023
a03b6e2
http version header to http connnector tool
ssd04 Sep 21, 2023
c2bb1a5
move CheckDuplicated to general config section
ssd04 Sep 22, 2023
aae6c87
fixes after review
ssd04 Sep 22, 2023
6b94802
fixes after review
ssd04 Sep 27, 2023
40e2cac
Merge pull request #82 from multiversx/websocket-payload-versioning
ssd04 Sep 28, 2023
283b106
update readme for ws integration
ssd04 Oct 2, 2023
cfc53d2
Merge branch 'rc/v1.6.0' into publisher-cli-param
ssd04 Oct 2, 2023
0f0982e
fix typo
ssd04 Oct 2, 2023
fb078a9
Merge pull request #81 from multiversx/publisher-cli-param
ssd04 Oct 2, 2023
8051ea9
use old txpool structure for v0
ssd04 Dec 15, 2023
0d17817
move test data structs to separate package
ssd04 Dec 15, 2023
017f726
update testing tools
ssd04 Dec 15, 2023
77fb490
fixes after review: refactorings
ssd04 Dec 15, 2023
0d71a6c
fixes after review: refactorings
ssd04 Dec 18, 2023
989e11c
Merge pull request #87 from multiversx/fix-old-data-unmarshall
ssd04 Dec 20, 2023
f6e6b5b
fix field in config
ssd04 Dec 21, 2023
756e5ba
update comment
ssd04 Dec 21, 2023
a03f032
update comment
ssd04 Dec 21, 2023
98db6cb
Merge pull request #88 from multiversx/fix-default-config-field
ssd04 Dec 21, 2023
fc20960
toml config unit tests
ssd04 Dec 22, 2023
d27eca0
Merge pull request #89 from multiversx/unit-tests-toml-config
ssd04 Dec 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@

logs
vendor

# python
__pycache__/
*.py[cod]
*$py.class
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ help:

build:
cd ${cmd_dir} && \
go build -o ${binary}
go build -v -ldflags="-X main.appVersion=$(git describe --tags --long --dirty)" -o ${binary}

api_type="rabbit-api"
publisher_type="rabbitmq"
run: build
cd ${cmd_dir} && \
./${binary} --api-type=${api_type} --log-level="*:DEBUG"
./${binary} --publisher-type=${publisher_type} --log-level="*:DEBUG"

runb: build
cd ${cmd_dir} && \
(./${binary} --api-type=${api_type} & echo $$! > ./${binary}.pid)
(./${binary} --publisher-type=${publisher_type} & echo $$! > ./${binary}.pid)

kill:
kill $(shell cat ${cmd_dir}/${binary}.pid)

debug: build
cd ${cmd_dir} && \
${debugger} exec ./${binary} -- --api-type=${api_type}
${debugger} exec ./${binary} -- --publisher-type=${publisher_type}

debug-ath:
${debugger} attach $$(cat ${cmd_dir}/${binary}.pid)
Expand All @@ -71,7 +71,7 @@ docker-new: docker-build
--network "host" \
--name ${container_name} \
${image}:${image_tag} \
--api-type ${api_type} --log-level="*:DEBUG"
--publisher-type ${publisher_type} --log-level="*:DEBUG"

docker-start:
docker start ${container_name}
Expand Down
65 changes: 22 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,17 @@ has to setup one or multiple observers. For running an observing squad,
these [docs](https://docs.multiversx.com/integrators/observing-squad/)
cover the whole process.

The observer node can be connected using WebSocket integration. Please check observer
node config for setting up the connector. Enable `HostDriversConfig` in order to use
WebSocket integration.

The required configs for launching an observer/s with a driver attached,
can be found [here](https://github.com/multiversx/mx-chain-go/blob/master/cmd/node/config/external.toml).

The supported config variables are as follows:

- `Enabled`: signals whether a driver should be attached when launching the node.
- `UseAuthorization`: signal whether to use authorization. For testing purposes it can be set to `false`.
- `ProxyUrl`: host and port on which the `eventNotifier` will push the parsed event data.
- `Username`: the username used for authorization.
- `Password`: the password used for authorization.

The corresponding config section for enabling the driver:

```toml
[EventNotifierConnector]
# Enabled will turn on or off the event notifier connector
Enabled = true

# UseAuthorization signals the proxy to use authorization
# Never run a production setup without authorization
UseAuthorization = false

# ProxyUrl is used to communicate with the subscriptions hub
# The indexer instance will broadcast data using ProxyUrl
ProxyUrl = "http://localhost:5000"

# Username and Password need to be specified if UseAuthorization is set to true
Username = ""
The HTTP integration is still available for backwards compatibility, but it will be
deprecated in the future.

# Password is used to authorize an observer to push event data
Password = ""
```

## Install
## How to run

Using the `cmd/notifier` package as root, execute the following commands:

Expand All @@ -55,29 +32,31 @@ Using the `cmd/notifier` package as root, execute the following commands:
---
This can also be done using a single command from `Makefile`:
```bash
# by default, rabbit-api type
# by default, rabbitmq type
make run

# specify notifier running mode (eq: rabbit-api, notifier)
make run api_type=rabbit-api
# specify notifier running mode (eq: rabbitmq, ws)
make run publisher_type=rabbitmq
```

## Launching the proxy

CLI: run `--help` to get the command line parameters
```bash
./cmd/notifier/event-notifier --help
```

### Prerequisites

Before launching the proxy (notifier) service, it has to be configured so that it runs with the
correct environment variables.
correct config variables.

The main config file can be found [here](https://github.com/multiversx/mx-chain-notifier-go/blob/main/cmd/notifier/config/config.toml).

The supported config variables are:
- `Host`: the host and port on which the http server listens on. Should be the same port
as the one specified in the `ProxyUrl` described above.
- `Username`: the username used to authorize an observer. Can be left empty for `UseAuthorization = false` on observer connector.
- `Password`: the password used to authorize an observer. Can be left empty for `UseAuthorization = false` on observer connector.
- `CheckDuplicates`: if true, it will check (based on a locker service using redis) if the event have been already pushed to clients

If observer connector is set to use BasicAuth with `UseAuthorization = true`, `Username` and `Password` has to be
set here on events notifier, and `Auth` flag has to be enabled in
Expand All @@ -90,14 +69,14 @@ For example:
{ Name = "/revert", Open = true, Auth = false },
```

The main config file can be found [here](https://github.com/multiversx/mx-chain-notifier-go/blob/main/cmd/notifier/config/config.toml).

After the configuration file is set up, the notifier instance can be
launched.

There are two ways in which notifier-go can be started:
* `notifier` mode: it will launch a websocket handler (check [WebSockets](#websockets) section)
* `rabbit-api` mode: it will set up a rabbitMQ client based on the RabbitMQ section from main config file (check [RabbitMQ](#rabbitmq) section)
There are multiple publishing options when starting notifier service:
* `ws`: it will launch a websocket handler (check [WebSockets](#websockets) section)
* `rabbitmq`: it will set up a rabbitMQ client based on the RabbitMQ section from main config file (check [RabbitMQ](#rabbitmq) section)

## Development setup

There is a development setup using docker containers (with
docker compose) that can be used for this.
Expand All @@ -113,7 +92,7 @@ events are being processed).
* `notifier` mode can be launched as following (check `Makefile` for details):
```bash
# Starts setup with one notifier instance
make docker-new api_type=notifier
make docker-new publisher_type=ws

# Stop notifier instance
make docker-stop
Expand All @@ -140,7 +119,7 @@ make compose-rm

Start Notifier instance
```bash
make docker-new api_type=rabbit-api
make docker-new publisher_type=rabbitmq
```

### API Endpoints
Expand Down
3 changes: 3 additions & 0 deletions api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ var ErrNilHTTPServer = errors.New("nil http server")

// ErrNilFacadeHandler signals that a nil facade handler has been provided
var ErrNilFacadeHandler = errors.New("nil facade handler")

// ErrNilPayloadHandler signals that a nil payload handler has been provided
var ErrNilPayloadHandler = errors.New("nil payload handler")
59 changes: 39 additions & 20 deletions api/gin/webServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/multiversx/mx-chain-communication-go/websocket"
"github.com/multiversx/mx-chain-core-go/core/check"
logger "github.com/multiversx/mx-chain-logger-go"
apiErrors "github.com/multiversx/mx-chain-notifier-go/api/errors"
Expand All @@ -23,21 +24,28 @@ const (

var log = logger.GetOrCreate("api/gin")

const (
eventsGroupID = "events"
hubGroupID = "hub"
)

// ArgsWebServerHandler holds the arguments needed to create a web server handler
type ArgsWebServerHandler struct {
Facade shared.FacadeHandler
Configs config.Configs
Facade shared.FacadeHandler
PayloadHandler websocket.PayloadHandler
Configs config.Configs
}

// webServer is a wrapper for gin.Engine, holding additional components
type webServer struct {
sync.RWMutex
facade shared.FacadeHandler
httpServer shared.HTTPServerCloser
configs config.Configs
groups map[string]shared.GroupHandler
wasTriggered bool
cancelFunc func()
facade shared.FacadeHandler
payloadHandler websocket.PayloadHandler
httpServer shared.HTTPServerCloser
groups map[string]shared.GroupHandler
configs config.Configs
wasTriggered bool
cancelFunc func()
}

// NewWebServerHandler creates and configures an instance of webServer
Expand All @@ -48,26 +56,30 @@ func NewWebServerHandler(args ArgsWebServerHandler) (*webServer, error) {
}

return &webServer{
facade: args.Facade,
configs: args.Configs,
groups: make(map[string]shared.GroupHandler),
wasTriggered: false,
facade: args.Facade,
payloadHandler: args.PayloadHandler,
configs: args.Configs,
groups: make(map[string]shared.GroupHandler),
wasTriggered: false,
}, nil
}

func checkArgs(args ArgsWebServerHandler) error {
if check.IfNil(args.Facade) {
return apiErrors.ErrNilFacadeHandler
}
if args.Configs.Flags.APIType == "" {
if args.Configs.Flags.PublisherType == "" {
return common.ErrInvalidAPIType
}
if check.IfNil(args.PayloadHandler) {
return apiErrors.ErrNilPayloadHandler
}

return nil
}

func (w *webServer) getWSAddr() string {
addr := w.configs.GeneralConfig.ConnectorApi.Host
addr := w.configs.MainConfig.ConnectorApi.Host
if addr == "" {
return defaultRestInterface
}
Expand Down Expand Up @@ -124,24 +136,31 @@ func (w *webServer) Run() error {
func (w *webServer) createGroups() error {
groupsMap := make(map[string]shared.GroupHandler)

eventsGroup, err := groups.NewEventsGroup(w.facade)
if err != nil {
return err
eventsGroupArgs := groups.ArgsEventsGroup{
Facade: w.facade,
PayloadHandler: w.payloadHandler,
}

if w.configs.MainConfig.ConnectorApi.Enabled {
eventsGroup, err := groups.NewEventsGroup(eventsGroupArgs)
if err != nil {
return err
}
groupsMap[eventsGroupID] = eventsGroup
}
groupsMap["events"] = eventsGroup

statusGroup, err := groups.NewStatusGroup(w.facade)
if err != nil {
return err
}
groupsMap["status"] = statusGroup

if w.configs.Flags.APIType == common.WSAPIType {
if w.configs.Flags.PublisherType == common.WSPublisherType {
hubHandler, err := groups.NewHubGroup(w.facade)
if err != nil {
return err
}
groupsMap["hub"] = hubHandler
groupsMap[hubGroupID] = hubHandler
}

w.groups = groupsMap
Expand Down
21 changes: 17 additions & 4 deletions api/gin/webServer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gin_test
import (
"testing"

"github.com/multiversx/mx-chain-communication-go/testscommon"
"github.com/multiversx/mx-chain-core-go/core/check"
apiErrors "github.com/multiversx/mx-chain-notifier-go/api/errors"
"github.com/multiversx/mx-chain-notifier-go/api/gin"
Expand All @@ -14,15 +15,16 @@ import (

func createMockArgsWebServerHandler() gin.ArgsWebServerHandler {
return gin.ArgsWebServerHandler{
Facade: &mocks.FacadeStub{},
Facade: &mocks.FacadeStub{},
PayloadHandler: &testscommon.PayloadHandlerStub{},
Configs: config.Configs{
GeneralConfig: config.GeneralConfig{
MainConfig: config.MainConfig{
ConnectorApi: config.ConnectorApiConfig{
Host: "8080",
},
},
Flags: config.FlagsConfig{
APIType: "notifier",
PublisherType: "notifier",
},
},
}
Expand All @@ -42,11 +44,22 @@ func TestNewWebServerHandler(t *testing.T) {
require.Equal(t, apiErrors.ErrNilFacadeHandler, err)
})

t.Run("nil payload handler", func(t *testing.T) {
t.Parallel()

args := createMockArgsWebServerHandler()
args.PayloadHandler = nil

ws, err := gin.NewWebServerHandler(args)
require.True(t, check.IfNil(ws))
require.Equal(t, apiErrors.ErrNilPayloadHandler, err)
})

t.Run("invalid api type", func(t *testing.T) {
t.Parallel()

args := createMockArgsWebServerHandler()
args.Configs.Flags.APIType = ""
args.Configs.Flags.PublisherType = ""

ws, err := gin.NewWebServerHandler(args)
require.True(t, check.IfNil(ws))
Expand Down
10 changes: 10 additions & 0 deletions api/groups/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package groups

import "errors"

var errNilBlockData = errors.New("nil block data")
var errNilTransactionPool = errors.New("nil transaction pool")
var errNilHeaderGasConsumption = errors.New("nil header gas consumption")

// ErrNilEventsDataHandler signals that a nil events data handler was provided
var ErrNilEventsDataHandler = errors.New("nil events data handler")
Loading
Loading