@@ -114,28 +114,62 @@ func (c *Client) Start() {
114
114
115
115
// Acquire starts the acquire process for the specified chain point
116
116
func (c * Client ) Acquire (point * common.Point ) error {
117
- var msg string
118
- if point != nil {
119
- msg = fmt .Sprintf (
120
- "calling Acquire(point: {Slot: %d, Hash: %x})" ,
121
- point .Slot ,
122
- point .Hash ,
117
+ // Use volatile tip if no point provided
118
+ if point == nil {
119
+ return c .AcquireVolatileTip ()
120
+ }
121
+ c .Protocol .Logger ().
122
+ Debug (
123
+ fmt .Sprintf (
124
+ "calling Acquire(point: {Slot: %d, Hash: %x})" ,
125
+ point .Slot ,
126
+ point .Hash ,
127
+ ),
128
+ "component" , "network" ,
129
+ "protocol" , ProtocolName ,
130
+ "role" , "client" ,
131
+ "connection_id" , c .callbackContext .ConnectionId .String (),
123
132
)
124
- } else {
125
- msg = "calling Acquire(point: latest)"
133
+ c .busyMutex .Lock ()
134
+ defer c .busyMutex .Unlock ()
135
+ acquirePoint := AcquirePoint {
136
+ Point : point ,
137
+ }
138
+ return c .acquire (acquirePoint )
139
+ }
140
+
141
+ func (c * Client ) AcquireVolatileTip () error {
142
+ c .Protocol .Logger ().
143
+ Debug (
144
+ "calling AcquireVolatileTip" ,
145
+ "component" , "network" ,
146
+ "protocol" , ProtocolName ,
147
+ "role" , "client" ,
148
+ "connection_id" , c .callbackContext .ConnectionId .String (),
149
+ )
150
+ c .busyMutex .Lock ()
151
+ defer c .busyMutex .Unlock ()
152
+ acquirePoint := AcquirePoint {
153
+ Volatile : true ,
126
154
}
155
+ return c .acquire (acquirePoint )
156
+ }
127
157
158
+ func (c * Client ) AcquireImmutableTip () error {
128
159
c .Protocol .Logger ().
129
160
Debug (
130
- msg ,
161
+ "calling AcquireImmutableTip" ,
131
162
"component" , "network" ,
132
163
"protocol" , ProtocolName ,
133
164
"role" , "client" ,
134
165
"connection_id" , c .callbackContext .ConnectionId .String (),
135
166
)
136
167
c .busyMutex .Lock ()
137
168
defer c .busyMutex .Unlock ()
138
- return c .acquire (point )
169
+ acquirePoint := AcquirePoint {
170
+ Immutable : true ,
171
+ }
172
+ return c .acquire (acquirePoint )
139
173
}
140
174
141
175
// Release releases the previously acquired chain point
@@ -906,19 +940,27 @@ func (c *Client) handleResult(msg protocol.Message) error {
906
940
return nil
907
941
}
908
942
909
- func (c * Client ) acquire (point * common. Point ) error {
943
+ func (c * Client ) acquire (acquirePoint AcquirePoint ) error {
910
944
var msg protocol.Message
911
945
if c .acquired {
912
- if point != nil {
913
- msg = NewMsgReAcquire (* point )
946
+ if acquirePoint .Point != nil {
947
+ msg = NewMsgReAcquire (* acquirePoint .Point )
948
+ } else if acquirePoint .Volatile {
949
+ msg = NewMsgReAcquireVolatileTip ()
950
+ } else if acquirePoint .Immutable {
951
+ msg = NewMsgReAcquireImmutableTip ()
914
952
} else {
915
- msg = NewMsgReAcquireNoPoint ( )
953
+ return fmt . Errorf ( "no acquire point provided" )
916
954
}
917
955
} else {
918
- if point != nil {
919
- msg = NewMsgAcquire (* point )
956
+ if acquirePoint .Point != nil {
957
+ msg = NewMsgAcquire (* acquirePoint .Point )
958
+ } else if acquirePoint .Volatile {
959
+ msg = NewMsgAcquireVolatileTip ()
960
+ } else if acquirePoint .Immutable {
961
+ msg = NewMsgAcquireImmutableTip ()
920
962
} else {
921
- msg = NewMsgAcquireNoPoint ( )
963
+ return fmt . Errorf ( "no acquire point provided" )
922
964
}
923
965
}
924
966
if err := c .SendMessage (msg ); err != nil {
@@ -944,7 +986,7 @@ func (c *Client) release() error {
944
986
func (c * Client ) runQuery (query interface {}, result interface {}) error {
945
987
msg := NewMsgQuery (query )
946
988
if ! c .acquired {
947
- if err := c .acquire (nil ); err != nil {
989
+ if err := c .acquire (AcquirePoint { Volatile : true } ); err != nil {
948
990
return err
949
991
}
950
992
}
0 commit comments