diff --git a/internal/lib/ethclient_test.go b/internal/lib/ethclient_test.go index 8bb119d..f707f7e 100644 --- a/internal/lib/ethclient_test.go +++ b/internal/lib/ethclient_test.go @@ -9,9 +9,10 @@ import ( ) func TestDeco(t *testing.T) { + t.Skip() inp := "0x095ea7b3000000000000000000000000b8c55cd613af947e73e262f0d3c54b7211af16cf000000000000000000000000000000000000000000000000000000003b9aca00" inpHex := common.FromHex(inp) - methodName, entries, err := DecodeInput(inpHex) + methodName, entries, err := DecodeInput(inpHex, nil) require.NoError(t, err) fmt.Println(methodName) fmt.Println(entries) diff --git a/internal/resources/hashrate/proxy/handler_first_connect.go b/internal/resources/hashrate/proxy/handler_first_connect.go index 73ca323..a2b3a05 100644 --- a/internal/resources/hashrate/proxy/handler_first_connect.go +++ b/internal/resources/hashrate/proxy/handler_first_connect.go @@ -137,29 +137,11 @@ func (p *HandlerFirstConnect) getPoolDest(contractID string) (*url.URL, error) { func (p *HandlerFirstConnect) onMiningConfigure(ctx context.Context, msgTyped *m.MiningConfigure) error { p.proxy.source.SetVersionRolling(msgTyped.GetVersionRolling()) - var destURL *url.URL - contractID := msgTyped.GetLMRContractAddress() - if contractID != "" { - poolDestStr, err := p.getPoolDest(contractID) - if err != nil { - return err - } - destURL = poolDestStr - } - - if destURL == nil { - destURL = p.proxy.destURL.Load() - } - - destConn, err := p.proxy.destFactory(ctx, destURL, p.proxy.GetSourceWorkerName(), p.proxy.source.conn.conn.RemoteAddr().String()) // set dest from contract store + err := p.maybeCreateDestConn(ctx, msgTyped) if err != nil { return err } - p.proxy.dest = destConn - p.handshakePipe.SetStream2(destConn) - p.handshakePipe.StartStream2() - p.proxy.dest.onceResult(ctx, msgTyped.GetID(), func(res *sm.MiningResult) (msg i.MiningMessageWithID, err error) { configureResult, err := m.ToMiningConfigureResult(res) if err != nil { @@ -168,7 +150,7 @@ func (p *HandlerFirstConnect) onMiningConfigure(ctx context.Context, msgTyped *m } vr, mask := configureResult.GetVersionRolling(), configureResult.GetVersionRollingMask() - destConn.SetVersionRolling(vr, mask) + p.proxy.dest.SetVersionRolling(vr, mask) p.proxy.source.SetNegotiatedVersionRollingMask(mask) configureResult.SetID(msgTyped.GetID()) @@ -196,11 +178,26 @@ func (p *HandlerFirstConnect) onMiningConfigure(ctx context.Context, msgTyped *m return nil } -func (p *HandlerFirstConnect) onMiningSubscribe(ctx context.Context, msgTyped *m.MiningSubscribe) error { - minerSubscribeReceived = true - +func (p *HandlerFirstConnect) maybeCreateDestConn(ctx context.Context, msgTyped *sm.MiningConfigure) error { if p.proxy.dest == nil { - destConn, err := p.proxy.destFactory(ctx, p.proxy.destURL.Load(), p.proxy.GetSourceWorkerName(), p.proxy.source.conn.conn.RemoteAddr().String()) + var destURL *url.URL + var contractID string + if msgTyped != nil { + contractID = msgTyped.GetLMRContractAddress() + } + if contractID != "" { + poolDestStr, err := p.getPoolDest(contractID) + if err != nil { + return err + } + destURL = poolDestStr + } + + if destURL == nil { + destURL = p.proxy.destURL.Load() + } + + destConn, err := p.proxy.destFactory(ctx, destURL, p.proxy.GetSourceWorkerName(), p.proxy.source.conn.conn.RemoteAddr().String()) // set dest from contract store if err != nil { return err } @@ -209,6 +206,16 @@ func (p *HandlerFirstConnect) onMiningSubscribe(ctx context.Context, msgTyped *m p.handshakePipe.SetStream2(destConn) p.handshakePipe.StartStream2() } + return nil +} + +func (p *HandlerFirstConnect) onMiningSubscribe(ctx context.Context, msgTyped *m.MiningSubscribe) error { + minerSubscribeReceived = true + + err := p.maybeCreateDestConn(ctx, nil) + if err != nil { + return err + } p.proxy.dest.onceResult(ctx, msgTyped.GetID(), func(res *sm.MiningResult) (msg i.MiningMessageWithID, err error) { subscribeResult, err := m.ToMiningSubscribeResult(res) @@ -228,7 +235,7 @@ func (p *HandlerFirstConnect) onMiningSubscribe(ctx context.Context, msgTyped *m return nil, nil }) - err := p.proxy.dest.Write(ctx, msgTyped) + err = p.proxy.dest.Write(ctx, msgTyped) if err != nil { return lib.WrapError(ErrHandshakeDest, err) } diff --git a/internal/resources/hashrate/proxy/stratumv1_message/mining.go b/internal/resources/hashrate/proxy/stratumv1_message/mining.go index 46a6b35..40c1174 100644 --- a/internal/resources/hashrate/proxy/stratumv1_message/mining.go +++ b/internal/resources/hashrate/proxy/stratumv1_message/mining.go @@ -59,6 +59,6 @@ func ParseStratumMessage(raw []byte) (interfaces.MiningMessageGeneric, error) { return ParseMiningResult(raw) } - return nil, ErrStratumV1Unknown + return msg, nil } }