@@ -83,9 +83,10 @@ func (r *RPCResponse) Message() string {
8383 return ""
8484}
8585
86- func (rc * RPCClient ) allocateRequestID (req * RPCRequest ) {
87- reqID := atomic .AddInt64 (& rc .requestCounter , 1 )
88- req .ID = fftypes .JSONAnyPtr (fmt .Sprintf (`"%.9d"` , reqID ))
86+ func (rc * RPCClient ) allocateRequestID (req * RPCRequest ) string {
87+ reqID := fmt .Sprintf (`%.9d` , atomic .AddInt64 (& rc .requestCounter , 1 ))
88+ req .ID = fftypes .JSONAnyPtr (`"` + reqID + `"` )
89+ return reqID
8990}
9091
9192func (rc * RPCClient ) CallRPC (ctx context.Context , result interface {}, method string , params ... interface {}) error {
@@ -119,13 +120,18 @@ func (rc *RPCClient) SyncRequest(ctx context.Context, rpcReq *RPCRequest) (rpcRe
119120 // multiple concurrent clients on our front-end that might use clashing IDs.
120121 var beReq = * rpcReq
121122 beReq .JSONRpc = "2.0"
122- rc .allocateRequestID (& beReq )
123+ rpcTraceID := rc .allocateRequestID (& beReq )
124+ if rpcReq .ID != nil {
125+ // We're proxying a request with front-end RPC ID - log that as well
126+ rpcTraceID = fmt .Sprintf ("%s->%s" , rpcReq .ID , rpcTraceID )
127+ }
128+
123129 rpcRes = new (RPCResponse )
124130
125- log .L (ctx ).Debugf ("RPC:%s:%s --> %s" , rpcReq . ID , rpcReq . ID , rpcReq .Method )
131+ log .L (ctx ).Debugf ("RPC[%s] --> %s" , rpcTraceID , rpcReq .Method )
126132 if logrus .IsLevelEnabled (logrus .TraceLevel ) {
127133 jsonInput , _ := json .Marshal (rpcReq )
128- log .L (ctx ).Tracef ("RPC:%s:%s INPUT: %s" , rpcReq . ID , rpcReq . ID , jsonInput )
134+ log .L (ctx ).Tracef ("RPC[%s] INPUT: %s" , rpcTraceID , jsonInput )
129135 }
130136 res , err := rc .client .R ().
131137 SetContext (ctx ).
@@ -138,21 +144,21 @@ func (rc *RPCClient) SyncRequest(ctx context.Context, rpcReq *RPCRequest) (rpcRe
138144 rpcRes .ID = rpcReq .ID
139145 if err != nil {
140146 err := i18n .NewError (ctx , signermsgs .MsgRPCRequestFailed )
141- log .L (ctx ).Errorf ("RPC[%d ] <-- ERROR: %s" , rpcReq . ID , err )
147+ log .L (ctx ).Errorf ("RPC[%s ] <-- ERROR: %s" , rpcTraceID , err )
142148 rpcRes = RPCErrorResponse (err , rpcReq .ID , RPCCodeInternalError )
143149 return rpcRes , err
144150 }
145151 if logrus .IsLevelEnabled (logrus .TraceLevel ) {
146152 jsonOutput , _ := json .Marshal (rpcRes )
147- log .L (ctx ).Tracef ("RPC:%s:%s OUTPUT: %s" , rpcReq . ID , rpcReq . ID , jsonOutput )
153+ log .L (ctx ).Tracef ("RPC[%s] OUTPUT: %s" , rpcTraceID , jsonOutput )
148154 }
149155 // JSON/RPC allows errors to be returned with a 200 status code, as well as other status codes
150156 if res .IsError () || rpcRes .Error != nil && rpcRes .Error .Code != 0 {
151- log .L (ctx ).Errorf ("RPC[%d ] <-- [%d]: %s" , rpcReq . ID , res .StatusCode (), rpcRes .Message ())
157+ log .L (ctx ).Errorf ("RPC[%s ] <-- [%d]: %s" , rpcTraceID , res .StatusCode (), rpcRes .Message ())
152158 err := fmt .Errorf (rpcRes .Message ())
153159 return rpcRes , err
154160 }
155- log .L (ctx ).Infof ("RPC:%s:%s <-- [%d] OK" , beReq . ID , rpcReq . ID , res .StatusCode ())
161+ log .L (ctx ).Infof ("RPC[%s] <-- [%d] OK" , rpcTraceID , res .StatusCode ())
156162 if rpcRes .Result == nil {
157163 // We don't want a result for errors, but a null success response needs to go in there
158164 rpcRes .Result = fftypes .JSONAnyPtr (fftypes .NullString )
0 commit comments