hyperledger-labs / perun-node

State channel node of the blockchain-agnostic state channels framework Perun.
https://labs.hyperledger.org/perun-doc/
Apache License 2.0
18 stars 12 forks source link

Watcher is started twice for each channel #154

Closed manoranjith closed 3 years ago

manoranjith commented 3 years ago

Description

The watcher routine is started each time a new channel is established. This can be identified from the logs of Test_Integ_Role, where the watcher would returned twice for each session ID for the same channel.

Screenshot from 2021-02-22 14-07-42

Relates to

Expected behaviour

That channel watcher should be started only once.

Current behaviour

The channel watcher is started twice for each channel.

Reproducing the behaviour

  1. cd session
  2. go test -cover -p 1 -count=1 -tags=integration -v -run Test_Integ_Role
  3. As highlighted in the picture, two instances of channel watcher can be identified.
Software version

3df8c4fc7258582890bde96a79bf7ab51946f701

Environment information
Expand to see output from `go env` command. ``` bash # Output of "go env" command GO111MODULE="" GOARCH="amd64" GOBIN="/mnt/data-work/go/bin" GOCACHE="/home/manoranjith/.cache/go-build" GOENV="/home/manoranjith/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/mnt/data-work/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/mnt/data-work/projects/perun/workspace/perun-node/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build111707423=/tmp/go-build -gno-record-gcc-switches" ```

Severity

Major (Breaks one or more features or specifications)

Frequency

Always

Additional information

This occurs because, each time a new channel is created by the go-perun SDK by invoking ProposeChannel or Accept call on channel proposal responder, the channel object is returned in two places:

  1. As a return value in the corresponding call.
  2. Passed to the OnNewChannel handler, that was registered when initializing the state channel client in go-perun SDK.

Solution to this bug would be that, after restoring the channels, the OnNewChannel handler should be unregistered by setting it to nil or a dummy handler. As it is convenient to process the channels that are received as return values (synchronously).