-
Notifications
You must be signed in to change notification settings - Fork 111
Conversation
Added --lightnode command line parameter Added LightNode to Handshake message
swarm/network/protocol.go
Outdated
} | ||
|
||
log.Info("peer created: %s", handshake.peerAddr.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a log.Debug
, otherwise logs will be full of it. Also use structured logs:
log.Debug("peer created", "addr", handshake.peerAddr.String())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed logging
swarm/network/protocol_test.go
Outdated
) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if pt.bzz.handshakes[id].LightNode != peerLightNode { | ||
t.Fatal(fmt.Sprintf("peer LightNode flag is %v, should be %v", pt.bzz.handshakes[id].LightNode, peerLightNode)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Fatalf
, instead of Fatal + Sprintf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to Fatalf
swarm/network/protocol_test.go
Outdated
@@ -30,6 +30,8 @@ import ( | |||
p2ptest "github.com/ethereum/go-ethereum/p2p/testing" | |||
) | |||
|
|||
const DefaultVersion = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a better name for this, and a godoc - what is this DefaultVersion
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to TestProtocolVersion
id := s.IDs[0] | ||
|
||
err := s.testHandshake( | ||
correctBzzHandshake(addr), | ||
&HandshakeMsg{Version: 0, NetworkID: 3, Addr: NewAddrFromNodeID(id)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have mixed feelings about changing the hardcoded values to extracted variables. The idea is - if someone changes the DefaultNetworkID
in the code, a test should fail, because this is changing the protocol and the contract. Peers would no longer be able to communicate.
You must know very well what you are doing when changing this, and I am afraid that hacking the actual value we tests against (in this case DefaultNetworkID
and Version
) has the opposite effect - tests will automatically pass, and you will notice that you changed the contract only once you deploy this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a new const called TestProtocolNetworkID
and used that in tests. I understand now that why using the DefaultNetworkID was a bad idea, however generally it's a good practice to not used hardcoded constants in the test code (or for that matter in any code), because it may lead to errors in unrelated tests when you change the constant in NetworkID tests.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with TestProtocolNetworkID
cmd/swarm/config.go
Outdated
@@ -303,6 +308,12 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) { | |||
} | |||
} | |||
|
|||
if lightnodeenable := os.Getenv(SWARM_ENV_LIGHT_NODE_ENABLE); lightnodeenable != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but this var
has a scope of 2 lines, it could very well be just lne
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the name to lne
swarm/network/protocol_test.go
Outdated
@@ -30,6 +30,8 @@ import ( | |||
p2ptest "github.com/ethereum/go-ethereum/p2p/testing" | |||
) | |||
|
|||
const DefaultVersion = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be 6
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to TestProtocolNetworkID. As far as I understand it can be anything that is not 0 based on the existing tests. Feel free to correct me if I am wrong.
swarm/network/protocol_test.go
Outdated
} | ||
} | ||
|
||
func TestBzzHandshakeLightNodeOn(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of those 2 tests? I think you only need one of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason I did two tests were to make sure it is set correctly independently of the default value. If we only check the On case (where LightNode
is True
), then it may happen that in the code it's set to True incorrectly buy tests wouldn't catch that.
I don't have a strong opinion about it but generally I think it doesn't hurt to have an extra test and it may cover errors as described above.
cmd/swarm/main.go
Outdated
@@ -123,6 +123,11 @@ var ( | |||
Usage: "Duration for sync subscriptions update after no new peers are added (default 15s)", | |||
EnvVar: SWARM_ENV_SYNC_UPDATE_DELAY, | |||
} | |||
SwarmLightNodeEnabled = cli.BoolTFlag{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that BoolFlag should be used instead BoolTFlag, if the default value is false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to BoolFlag
There were the following issues with your Pull Request
Guidelines are available at https://github.com/ethersphere/go-ethereum This message was auto-generated by https://gitcop.com |
@@ -30,6 +30,11 @@ import ( | |||
p2ptest "github.com/ethereum/go-ethereum/p2p/testing" | |||
) | |||
|
|||
const ( | |||
TestProtocolVersion = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version is 5. You are changing the handshake message, which means that you need to bump this to 6, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bumped it to 6 to reflect the fact that the handshake is changed. However I think changing here has little significance, because it is only used in the scope of these tests and it is only used in one test for comparing with zero.
I think in order to change it in the protocol, one has to change the version in the BzzSpec
that is inside swarm/network/protocol.go
.
Also I remember in one of our hangout calls that it may not be necessary to bump this, @janos can you chime in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I was wrong about the significance of changing this in the tests, because if I change it there and not in BzzSpec
the tests will fail.
Still the question is valid, should we change it in BzzSpec
and therefore here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran some tests.
If we change the version, then nodes running version 6 won't connect to nodes that are running version 5 (as expected).
However if we just add the LightNode flag to the handshake without changing the version, the nodes are able to connect to each other. This is a bit surprising to me, but this means it's not strictly necessary to change the version at this point, because currently the code doesn't change any functionality.
In any case in the future it seems like a good idea to bump the version when add the actual LightNode functionality to Kademlia, because from that point nodes will definitely work differently, hence the need for the version change.
So I think the question is should we change the version two times (now and when the Kademlia changes are implemented) or just once (only after the Kademlia changes)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that adding a field to a message is not a breaking change for protocol. It just requires that default value should be handled, and since default for light node flag is false, then it is handled implicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I thought nodes won't be able to deserialise the new value. If they can, then perfect!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janos That's what my experiment suggests too, that just adding a LightNode
field to the Handshake
message works even when connecting to nodes which do not support the LightNode
flag.
So basically you suggest that we keep the version right now at 5 and change it to 6 when we actually introduce breaking change in the functionality in Kademlia? @nonsense wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, kept the version at 5 right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently I don't understand exactly the RLP serialization - will play with this locally, and I trust you that it works. Since this is the case, keep it at 5, no need to upgrade.
@@ -225,16 +240,59 @@ func TestBzzHandshakeVersionMismatch(t *testing.T) { | |||
} | |||
|
|||
func TestBzzHandshakeSuccess(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following 3 tests are basically identical. I think this is introducing too much code with too little test value. Please create one test with a table-driven params, where you have both options - light node on/off. https://github.com/golang/go/wiki/TableDrivenTests
swarm/network/protocol_test.go
Outdated
if pt.bzz.handshakes[id].LightNode != peerLightNode { | ||
t.Fatalf("peer LightNode flag is %v, should be %v", pt.bzz.handshakes[id].LightNode, peerLightNode) | ||
} | ||
var lightNodeTests = []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This var should be scoped within the test, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the var inside the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that the Go 1.9 test is flaky and that's why the Travis build failed? Have you seen similar before? |
@agazso yes, you are hitting a flaky test on the Go 1.9 build. Ignore or click rebuild. This one in particular is quite rare. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@agazso We are getting a lot of errors in the open cluster, which includes this PR:
This is the backward-incompatible change I mentioned, and this is why I wanted to bump up the protocol version. How did you test this to come to the conclusion that RLP can handle both versions of the HandshakeMsg? |
@nonsense That is correct, it is indeed backward incompatible, my tests were incomplete before. I agree that we should bump the protocol version. The question is how should we do it, because depending on the versioning schema swarm uses, the swarm version should be changed to reflect it is a backward incompatible change. For example with semver it's a minor version change. |
|
@nonsense Sorry, I am a bit confused :) To my understanding we changed the network API in a way that is backwards incompatible. People who are using Swarm may expect that change is reflected in a Swarm version number change. I don't know the policy of Swarm dealing about these cases. It's easy just to bump the protocol version, I am asking about the specific steps to do that:
|
We changed the API in a non-backward compatible way with this PR, and it has already been merged. Nodes no longer can connect to each other, and we are currently still using the same version for the protocol, which is bad. We should at least increase the protocol version. This will be released with 0.3.2 , which won't be compatible with 0.3.1, because of this change. I hope that makes sense. |
Added --lightnode command line parameter
Added LightNode to Handshake message
This is the Task0 of the Light Node implementation.
For more details see https://hackmd.io/O5PvHQVhQnaNCbhJbAJVog?view