mirror of https://github.com/hyperledger/besu
Add plugin API to select Transactions (#5396)
This API fulfils the basic requirements, but will probably be extended in the near future. Signed-off-by: Stefan <stefan.pingel@consensys.net> Signed-off-by: Stefan Pingel <16143240+pinges@users.noreply.github.com> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>pull/5495/head
parent
f121f12ead
commit
65bcc557e4
@ -0,0 +1,37 @@ |
||||
/* |
||||
* Copyright contributors to Hyperledger Besu. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.services; |
||||
|
||||
import org.hyperledger.besu.plugin.services.TransactionSelectionService; |
||||
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
/** The Transaction Selection service implementation. */ |
||||
public class TransactionSelectionServiceImpl implements TransactionSelectionService { |
||||
|
||||
private Optional<TransactionSelectorFactory> factory = Optional.empty(); |
||||
|
||||
@Override |
||||
public Optional<TransactionSelectorFactory> get() { |
||||
return factory; |
||||
} |
||||
|
||||
@Override |
||||
public void registerTransactionSelectorFactory( |
||||
final TransactionSelectorFactory transactionSelectorFactory) { |
||||
factory = Optional.ofNullable(transactionSelectorFactory); |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.besu.plugin.data; |
||||
|
||||
/** Enum for the transaction selection result */ |
||||
public enum TransactionSelectionResult { |
||||
/** remove transaction from pool and continue block building */ |
||||
DELETE_TRANSACTION_AND_CONTINUE, |
||||
/** continue block building */ |
||||
CONTINUE, |
||||
/** stop block building */ |
||||
COMPLETE_OPERATION |
||||
} |
@ -0,0 +1,40 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.besu.plugin.services; |
||||
|
||||
import org.hyperledger.besu.plugin.Unstable; |
||||
import org.hyperledger.besu.plugin.services.txselection.TransactionSelectorFactory; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
/** Transaction selection service interface */ |
||||
@Unstable |
||||
public interface TransactionSelectionService extends BesuService { |
||||
|
||||
/** |
||||
* Returns the (Optional) transaction selector factory |
||||
* |
||||
* @return the transaction selector factory |
||||
*/ |
||||
Optional<TransactionSelectorFactory> get(); |
||||
|
||||
/** |
||||
* Registers the transaction selector factory with the service |
||||
* |
||||
* @param transactionSelectorFactory transaction selector factory to be used |
||||
*/ |
||||
void registerTransactionSelectorFactory(TransactionSelectorFactory transactionSelectorFactory); |
||||
} |
@ -0,0 +1,39 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.besu.plugin.services.txselection; |
||||
|
||||
import org.hyperledger.besu.plugin.Unstable; |
||||
import org.hyperledger.besu.plugin.data.Transaction; |
||||
import org.hyperledger.besu.plugin.data.TransactionReceipt; |
||||
import org.hyperledger.besu.plugin.data.TransactionSelectionResult; |
||||
|
||||
/** Interface for the transaction selector */ |
||||
@Unstable |
||||
public interface TransactionSelector { |
||||
|
||||
/** |
||||
* Method called to decide whether a transaction is added to a block. The method can also indicate |
||||
* that no further transactions can be added to the block. |
||||
* |
||||
* @param transaction candidate transaction |
||||
* @param receipt receipt for the candidate transaction |
||||
* @return TransactionSelectionResult that indicates whether to include the transaction |
||||
*/ |
||||
default TransactionSelectionResult selectTransaction( |
||||
final Transaction transaction, final TransactionReceipt receipt) { |
||||
return TransactionSelectionResult.CONTINUE; |
||||
} |
||||
} |
@ -0,0 +1,30 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
package org.hyperledger.besu.plugin.services.txselection; |
||||
|
||||
import org.hyperledger.besu.plugin.Unstable; |
||||
|
||||
/** Interface for a factory that creates transaction selectors */ |
||||
@Unstable |
||||
public interface TransactionSelectorFactory { |
||||
|
||||
/** |
||||
* Create a transaction selector |
||||
* |
||||
* @return the transaction selector |
||||
*/ |
||||
TransactionSelector create(); |
||||
} |
Loading…
Reference in new issue