Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion internal/lib/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 32 additions & 25 deletions internal/resources/hashrate/proxy/handler_first_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ func ParseStratumMessage(raw []byte) (interfaces.MiningMessageGeneric, error) {
return ParseMiningResult(raw)
}

return nil, ErrStratumV1Unknown
return msg, nil
}
}
Loading